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

No way to pass free arguments to a specific place #155

Open
ItsDrike opened this issue Jul 8, 2023 · 3 comments
Open

No way to pass free arguments to a specific place #155

ItsDrike opened this issue Jul 8, 2023 · 3 comments
Labels
enhancement New feature or request Seeking feedback
Milestone

Comments

@ItsDrike
Copy link

ItsDrike commented Jul 8, 2023

With shell scripts, it's possible to do something like: python -m robot --pythonpath . -d ./outptut "$@" tests, so that when you call a script, the passed arguments are forwarded to the command in a specific location.

However with poe a task like:

[tool.poe.tasks.test]
help = "Run all tests"
cmd = "python -m robot --pythonpath . -d ./output ./tests"

Any passed arguments will simply be appended to the end of the command. This isn't ideal, as some CLI tools only support usage like: robot [options] paths, which means any positional arguments left after the options are interpreted as paths. This means that running for example: robot --pythonpath . ./tests -d ./output wouldn't work, and I'd get an error that it couldn't find -d as a path.

I'd love to see a feature that would allow for me to pass arguments to a specific place in my command.

@nat-n nat-n added enhancement New feature or request Seeking feedback labels Jul 8, 2023
@nat-n
Copy link
Owner

nat-n commented Jul 9, 2023

Hi @ItsDrike,

I agree this is an issue, but I've not managed to find a good solution yet. One difficulty is that I haven't found a robust way to pass arguments to a shell child process (to populate $@ within the shell) where the script content is being passed via stdin (which is how shell tasks work). Rethinking shell tasks as discussed in #64 might help, but that's a way off on the roadmap.

Thinking allowed here, maybe just having a way to capture extra arguments (either when there are no args defined, or when provided after the -- on the command line) and being able to specifically inject them at a certain point in a command rather than append them to the end is all that's needed? Need to think this through a bit...

I'm open to ideas.

That said, one imperfect solution that might just work for you is to define a positional arg on your task that accepts multiple values. For example given a task like:

[tool.poe.tasks.show-args]
cmd = """
python -c "import sys; print(sys.argv[1:])" being $all_args end
"""
args = [{ name = "all_args", positional = true, multiple = true }]

And a command like:

poe show-args middle "multiple words" -- and then some

The result will be:

Poe => python -c import sys; print(sys.argv[1:]) begin middle multiple words end and then some
['begin', 'middle', 'multiple', 'words', 'end', 'and', 'then', 'some']

A couple of points to pay attention to:

  1. you can also accept multiple values for cli options, but args multiple must come first in the command. Accepting multiple values for multiple args gets complicated quickly
  2. the multiple values are essentially just passed as a whitespace delimited string which is then lexed into multiple words inside the task. If you don't want this then put quotes around the "${variable}" just like in a normal POSIX shell.

@roniemartinez
Copy link

I was hoping to migrate from Makefile to a better tool and found this library.

I found a similar limitation with regards to running command inside a docker container. For example when running Django commands, I have to do docker-compose run --rm server bash -c "python manage.py makemigrations" but most of the commands need extra arguments to be passed. This is not possible with the tool because we need to put the command inside quotes/double quotes.

I also used go-tasks for a while and I think I am looking for something similar to {{.CLI_ARGS}} (https://taskfile.dev/usage/#forwarding-cli-arguments-to-commands)

@merlinz01
Copy link

I agree that poe should have a way to do this.

You can put arguments in an environment variable and use it wherever the arguments are going to be passed:

[tool.poe.tasks.test]
sequence = [
    { cmd = 'pytest $TEST_ARGS' },
    { cmd = 'some other command' }
]

TEST_ARGS="-n auto" poe test

Which isn't very elegant but at least it works.

@nat-n nat-n added this to the 1.0.0 milestone Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Seeking feedback
Projects
None yet
Development

No branches or pull requests

4 participants