nat-n / poethepoet

A task runner that works well with poetry.
https://poethepoet.natn.io/
MIT License
1.4k stars 58 forks source link

Task args provided are not being parsed: "the following arguments are required" #68

Closed chris-twosense closed 2 years ago

chris-twosense commented 2 years ago

I am trying to set up a poe task which runs a script with a single argument:

[[tool.poe.tasks.download-env]]
shell = "./scripts/download-env.sh"
help = "Download an environment profile"

    [[tool.poe.tasks.download-env.args]]
    name = "profile"
    help = "The name of the environment profile to download"
    default = "dev"
    options = ["-p", "--profile"]
    required = true

Running the above task produces the following error:

% poetry run poe download-env --profile dev    
usage: poe download-env[0] -p PROFILE
poe download-env[0]: error: the following arguments are required: -p/--profile

I have tried running this from a clean project, bash, zsh, as well as removing around with the "required" option, which produces the following:

poetry run poe download-env --profile staging
Poe the Poet - A task runner that works well with poetry.
version 0.13.1

Error: Sequence task 'download-env' does not accept arguments 
...

I am unsure if this is an issue with the project or my environment but as I've been unable to find much documentation on the issue I figured this is the best forum to ask. Thanks!

nat-n commented 2 years ago

Hi @chris-twosense, thanks for reporting this.

Something is definitely wrong here. I should have time to look into it next week.

nat-n commented 2 years ago

Hi @chris-twosense, It took me a couple of minutes of debugging to spot it, but there's a subtle error in your example.

[[tool.poe.tasks.download-env]]

There should be only single square brackets around the task name header. Having double square brackets makes it a key with a value that is an array containing the task config, instead of just the task config directly as the value.

This means that you get

tool.poe.tasks.download-env = [{...}]

instead of just

tool.poe.tasks.download-env = {...}

This causes the task to be interpreted as a sequence task containing a shell task, which means there's no way to pass the arguments to the shell task defined inside the sequence.

I've taken a note that poe should catch this kind of error in the config validation stage to make such errors easier to avoid, but I believe the resolution of your issue is just to remove the excess brackets :)