Jaymon / captain

command line python scripts for humans
MIT License
13 stars 1 forks source link

Over-riding values still isn't completely working as expected #75

Closed Jaymon closed 3 weeks ago

Jaymon commented 1 year ago
class Foo(Command):
 @arg(
        "foos",
        metavar="FOO",
        nargs="*",
        dest="foo_names",
        help="foo help 1"
    )
    def handle(self, *args, **kwargs): pass

class Bar(Command):
 @args(Foo)
 @arg(
        "foos",
        nargs="+",
        dest="foo_names",
        help="foo help 2"
    )
    def handle(self, *args, **kwargs): pass

I would expect the merged foo_names to roughly look like this:

args:
  foos

kwargs:
  nargs: +
  dest: foo_names
  help: foo help 2

But that didn't seem to be the case, I had to add metavar to the child one to get it to look as expected.

Jaymon commented 3 weeks ago

Turns out, this isn't actually a bug and merging is working correctly, previously I was compensating for a positional argument having an arg ("foos") and a dest ("foo_names") by moving the arg to the metavar and then setting the dest as the arg, so the signature switched to "foo_names", metavar="foos" and then when the arguments were merged the "foos" metavar would override the "FOO" metavar. I think it's better to adhere to the default behavior rather than compensate for a bad signature