chriskiehl / Gooey

Turn (almost) any Python command line program into a full GUI application with one line
MIT License
20.58k stars 1.02k forks source link

Required/Positional arguments and double dash ("--") #847

Open sebtoun opened 1 year ago

sebtoun commented 1 year ago

Hi,

I'm trying to use Gooey with python-fire and am having trouble with required (positional) arguments. It seems that Gooey is always passing positional arguments at the end of command line after a "--" but python-fire seems to not accept this form.

Why does Gooey passes positional arguments this way and would it be possible to opt out from this behavior ?

Just to clarify my use case:

parser = GooeyParser()
sub_parsers = parser.add_subparsers()
action = sub_parsers.add_parser("action")
action.add_argument("folder", type=str, widget="DirChooser")
action.add_argument("--force", action='store_true', default=False)

With the configuration above, Gooey generates the following command line parameters:

action --force -- <folder>

While python fire expects:

action <folder> --force

or

action --force <folder>

Thanks!

jsoma commented 1 year ago

I don't know enough about argparse/gooey to know why this is, but it looks like if you change the nargs parameter to "*" or "?" parameters become optional, and get positioned in the place you're expecting.

action.add_argument("folder", type=str, widget="DirChooser", nargs="?")

Are there downsides to using nargs or having your argument categorized as optional? No idea, but at least it seems to work!

And to help a past version of myself with search terms: -- is a "double dash" or a double hyphen.

sebtoun commented 1 year ago

Thanks for the tip ! I ended up using

action.add_argument("--folder", type=str, widget="DirChooser")

and explicit argument groups using add_argument_group to make arguments look like required.