jaraco / cmdix

Fork of https://launchpad.net/pycoreutils
MIT License
27 stars 1 forks source link

env attempts to parse options in the command #14

Closed jaraco closed 11 months ago

jaraco commented 11 months ago

Consider this invocation:

 @ env PYTHONPATH=devtools/py py -m switch-track --help
usage: env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]

Set each NAME to VALUE in the environment and run COMMAND.

positional arguments:
  inputs

options:
  -h, --help            show this help message and exit
  -i, --ignore-environment
                        start with an empty environment

or

 @ env PYTHONPATH=devtools/py py -m switch-track
usage: env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]
env: error: unrecognized arguments: -m switch-track

The arg parsing is failing because the -m and --help are being parsed for env. env needs to ignore any options after the first argument is encountered.

jaraco commented 11 months ago

I notice the [-] in the usage. However, injecting a - ahead of the command seems to have no effect. I did find, by checking the argparse docs, that injecting -- ahead of the command args does force them to be passed through to the subprocess command.

That option isn't available on env for macOS, but I do see it on Linux, where:

A mere - implies -i.

Probably cmdix should mimic that behavior for compatibility.