Command line argument parsing

Write codeEasy16 min

Your task

A deploy tool reads its own argument vector rather than pulling in a parser. Scan argv left to right. A token that is exactly "--" closes option scanning, and every token after it is a plain argument. Until then: a token starting with "--" is a long option, where "--name=value" splits on its first "=" only (the value may be empty) and "--name" alone is worth "true"; a token starting with a single dash and holding at least one more character is a bundle whose every remaining character is a switch worth "true". Anything else, a lone "-" included, is a plain argument and sets nothing. Setting a name twice keeps the newer value at the older position. Return one "name=value" string per distinct name, ordered by where each name first appeared.

Examples

resolve_cli_options(argv: list[str]) -> list[str]
Example 1
Inputresolve_cli_options(["deploy", "--env=staging", "-vq", "--dry-run", "--", "--force", "app.zip"])
Output["env=staging", "v=true", "q=true", "dry-run=true"]
Example 2
Inputresolve_cli_options(["--tag=rc1", "--tag=rc2", "-t"])
Output["tag=rc2", "t=true"]
Example 3
Inputresolve_cli_options(["--path=/opt/tools=bin"])
Output["path=/opt/tools=bin"]