Core flags after a task name are silently consumed as positional values (same root cause as #982, beyond --help)
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 72/100
Research direction
Start in Parser.handle, using the reproductions for build --echo, --dry, --debug, and --warn-only as the baseline. Compare the existing --help handling from #1078 with the positional-argument branch. Done means each core flag takes effect after a task name instead of being consumed as the target value, including preventing real execution for --dry.
Written by the indexing model from the issue text.
Description
#982 / #1078 fixed this for --help, but the same defect applies to every other core flag when given after a task name whose positional arguments are not yet filled: the flag is silently consumed as the positional value and the task runs instead of the flag taking effect.
Version: invoke 3.0.3 (release) and current master. Python 3.13, Windows.
Repro
# tasks.py
from invoke import task
@task
def build(ctx, target):
print(f"BUILDING {target}")
$ invoke build --echo
BUILDING --echo # task RAN; echo mode not enabled
$ invoke build --dry
BUILDING --dry # "dry run" executed for real
$ invoke build --debug
BUILDING --debug
$ invoke build --warn-only
BUILDING --warn-only
All four core flags are swallowed as the value of the still-unfilled target positional. Same happens on current master (verified). The --help case was fixed in #1078 by checking it before the positional branch; that PR's commentary explicitly scoped everything else out ("Unlike other initial-context flags..."), but the remaining flags have exactly the same never-a-valid-positional property — no task legitimately wants the literal string --echo as data.
Why this is worse than it looks
--dry being swallowed means a user who believes they are doing a dry run actually executes destructive tasks against real targets. That's a safety-relevant failure mode, not just an inconvenience.
Proposed direction
Generalize the #1078 approach: before the positional-arg branch in Parser.handle, treat any token matching an initial-context core flag as that flag (setting its value / entering flag state), regardless of pending positionals. If backwards compatibility concerns exist for tasks that genuinely accept e.g. --echo as a task-level flag — note those are matched per-context later anyway, so initial-context handling can stay reserved for core flags.
Happy to send a PR generalizing #1078's fix if maintainers agree on the semantics.
- Dominant language
- Python
- Stars
- 4.8k
- Forks
- 412
- PR merge metrics
- No merged PRs in 30d
Getting set up
We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.
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
-
[Security] Shell injection via Context.cd() path argument — metacharacters not escaped (CWE-78)Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
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
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
PedestrianDynamics/pyFDS-Evac#199 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
521xueweihan/HelloGitHub#3790 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
sandialabs/atlas-ui-3#978 ·
Maintainers usually reply within 1 day
-
area: tests perceived difficulty: 2
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Nitjsefnie-Harness-Commons/daedalus#1255 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
EleutherAI/lm-evaluation-harness#4256 ·
Maintainers usually reply within 1 day