facebookarchive / python-nubia

A command-line and interactive shell framework.
Other
1.59k stars 95 forks source link

Command @argument description required? #27

Closed docent-net closed 5 years ago

docent-net commented 5 years ago

Got a problem when using the following decorators set:

    @argument("profile", positional=True, choices=aws_profiles)
    @argument("host", positional=True)
    def ssh(self, profile, host):

When invoking app got:

  File "/home/somewhere-else/cyk/cyk/app.py", line 9, in <module>
    shell = Nubia(name="cyk_shell", plugin=plugin)
  File "/home/somewhere/pyenv/versions/cyk/lib/python3.6/site-packages/nubia/internal/nubia.py", line 127, in __init__
    self._registry.register_command(cmd, override=True)
  File "/home/somewhere/pyenv/versions/cyk/lib/python3.6/site-packages/nubia/internal/registry.py", line 67, in register_command
    cmd_instance.add_arguments(self._parser)
  File "/home/somewhere/pyenv/versions/cyk/lib/python3.6/site-packages/nubia/internal/cmdbase.py", line 485, in add_arguments
    register_command(parser, self.metadata)
  File "/home/somewhere/pyenv/versions/cyk/lib/python3.6/site-packages/nubia/internal/typing/argparse.py", line 143, in register_command
    register_command(subcommand_parsers, v)
  File "/home/somewhere/pyenv/versions/cyk/lib/python3.6/site-packages/nubia/internal/typing/argparse.py", line 114, in register_command
    arg
  File "/home/somewhere/pyenv/versions/cyk/lib/python3.6/site-packages/nubia/internal/typing/argparse.py", line 228, in _argument_to_argparse_input
    ", ".join(map(str, arg.choices))
TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str'

And it makes sense; looks like add_argument_kwargs["help"] is NoneType when command description is not provided:

add_argument_kwargs["help"] += " (choose from {})".format(
            ", ".join(map(str, arg.choices))
        )

Not sure now if this is intended (thus documentation lacks information about required options) or not. I could fix this in argparse.py and make description optional or simply update docs :)

AhmedSoliman commented 5 years ago

Yes, description is required. It would be nice if you send a doc update PR. Will be happy to accept it.

motohedgehog commented 5 years ago

Closed by #29.