Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra arguments apart from what is declared, are not attached correctly #69

Closed
smac89 opened this issue May 12, 2022 · 2 comments
Closed

Comments

@smac89
Copy link

smac89 commented May 12, 2022

I just want to add a disclaimer: I'm not sure whether poe was designed the accept extra arguments beyond what was declared for a task, but I noticed that supplying extra args after -- seems to include the extra arguments, so that's what I was trying here

For example, given the following task declaration:

[tool.poe.env]
PYTHONPATH = "${PWD}/examples"
DJANGO_SETTINGS_MODULE = "config.settings"

[tool.poe.tasks.migrate]
cmd = "django-admin migrate --pythonpath ${PWD}/examples/$example"
args = [{name = "example", default = "my_app_example", positional = true}]
envfile = ".env"

If I run it using poe migrate -- --help, poe will translate it to:

django-admin migrate --pythonpath /home/username/projects/my_django_app/examples/--help

This causes an error because as you can see, there is no space between the last argument and --help, however without the extra -- --help, everything works, but I can't pass more arguments to the command.

Please help me know if this is defined behavior and how to work around it, or whether it's a bug. Thanks

@nat-n
Copy link
Owner

nat-n commented May 18, 2022

Hi @smac89, thanks for the feedback!

The CLI argument parser does not give any special meaning to --, it simple passes it to argparse like another argument. Now it appears to be an "undocumented feature" of the argparse module that anything following -- in the list of arguments is taken as positional argument. In the context of how argparse is used this follows POSIX CLI convention.

So what I believe is happening in your example is that --help is actually being parsed as the example positional argument.

Relevant code is around here.

As for the question of what should poe do with -- in the arguments list? Earlier I considered using it for invoking multiple tasks in one line, but wasn't sure it would work well. Maybe passing all remaining arguments to the command as you say would make sense, a bit like how npm does it.

I need to sleep on it. I'm open to arguments one way or another about how to best handle this.

nat-n added a commit that referenced this issue Mar 5, 2023
#69

Any tokens in the argument list from the first -- are ignored for the
purpose of parsing declared cli arguments.
nat-n added a commit that referenced this issue Mar 22, 2023
#69

Any tokens in the argument list from the first -- are ignored for the
purpose of parsing declared cli arguments.
nat-n added a commit that referenced this issue Mar 22, 2023
@nat-n
Copy link
Owner

nat-n commented Mar 22, 2023

This was shipped in 0.19.0 🙂

@nat-n nat-n closed this as completed Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants