Recommended way to forward arguments to commands
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
Research direction
Start with Invoke's command-line parsing and Context entry points, focusing on the -- delimiter described in the issue. Determine whether forwarding is intended or needs an explicit API; done means the supported behavior is documented or the requested Context handling is specified and covered by an appropriate test.
Written by the indexing model from the issue text.
Description
It'd like to know the recommended way to forward arguments to a command. For example, I have a test task that runs PyTest and I'd like to forward any extra arguments along to pytest. The best way I've found to do this is delimit my task's arguments from those of pytest with --. If I do this invoke seems to ignore all the following arguments. Ultimately this means I can do the following:
import sys
from invoke import task
try:
EXTRA_ARGS = sys.argv[sys.argv.index("--") + 1: ]
except ValueError:
EXTRA_ARGS = []
@task
def test(ctx):
ctx.run(f"pytest {' '.join(EXTRA_ARGS)}"
Where usage could then be:
invoke test -- test_something.py::test_feature --maxfail=2
While this works, I searched through the documentation and even a bit of the code, but didn't see anything that would explicitly allow for this sort of "argument forwarding" pattern. Is this behavior intended or is there a better way to achieve this? If it is something that invoke intentionally supports, perhaps these extra args (everything following --) could be attached to the Context.
- Dominant language
- Python
- Stars
- 4.8k
- Forks
- 412
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pyinvoke/invoke
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Similar issues
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
simonw/sqlite-utils#872 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100