docopt-ng icon indicating copy to clipboard operation
docopt-ng copied to clipboard

Warning message incomprehensible for end-user

Open thorstenkampe opened this issue 6 years ago • 5 comments

Wenn I run my script without a necessary subcommand, docopt-ng issues a warning - shouldn't it be an error? - which in my opinion is not suitable for the enduser (found unmatched (duplicate?) arguments [Argument(None, '...')].

Even I as the script writer, don't know what that exactly means. It looks to me like docopt-ng exposes internals from the parsing process which should not be given to the script user.

> python interpreter.py '.\10. PowerShell.ps1'
Warning: found unmatched (duplicate?) arguments [Argument(None, '.\\10. PowerShell.ps1')]
Usage:
 interpreter.py run <script> [-- <script_option> ...]
 interpreter.py doc [-s <text>] <script>

thorstenkampe avatar Sep 27 '19 14:09 thorstenkampe

I had the same issue but fixed it through trial and error. I had something like this:

Usage:
  script.py (--save | --load) FILE

Arguments:
  FILE                     

Options:
  --save FILE
  --load FILE

The error message was:

$ python script.py --save file.ini
Warning: found unmatched (duplicate?) arguments [Option(None, '--save', 1, 'file.ini')]

Removing FILE after --save in Options: did the trick for me.

loelkes avatar Nov 07 '19 22:11 loelkes

The error message presented is confusing.

Provided the following:

"""CLI

Usage:
  cli <arg1> <arg2>

"""
from docopt import docopt


def main():
    """MVE of confusing error"""
    arguments = docopt(__doc__, version="1.0.0")
    print(arguments)


if __name__ == "__main__":
    main()

The command line behavior is:

$ cli 
Usage:
  cli <arg1> <arg2>

$ cli 1 2
{'<arg1>': '1',
 '<arg2>': '2'}

$ cli 1 
Warning: found unmatched (duplicate?) arguments [Argument(None, '1')]
Usage:
  cli <arg1> <arg2>

The error message provided above should instead tell the command-line user that they need to specify a second argument.

I note for clarity that the help and version features work despite being undocumented.

$ cli --help
CLI

Usage:
  cli <arg1> <arg2>

$ cli -h
CLI

Usage:
  cli <arg1> <arg2>

$ cli --version
1.0.0

jambonrose avatar Jan 15 '20 22:01 jambonrose

I was running into this issue as well and it ended up being because I was calling docopt(..., options_first=True, ...) and it was evaluating differently than I expected, which was causing the unclear error message. Removing that option resolved it in my case.

traviswaelbro avatar May 03 '23 19:05 traviswaelbro