File task #USAGE variables inherit stale usage_* env vars when omitted #9460
Replies: 1 comment
|
Follow-up after digging into The key distinction is that That gives a few distinct modes: # No default: omission preserves any inherited value.
# This can be used as an ambient/default-from-caller channel, but it is risky for nested tasks.
#USAGE flag "--model <model>"
#USAGE arg "[message]"# Explicit defaults: omission overwrites inherited values and makes the task invocation-local.
# Good default for most mise file tasks.
#USAGE flag "--headless" default=#false
#USAGE flag "--model <model>" default=""
#USAGE arg "[message]" default=""# Variadic/repeatable values can also be cleared with an empty default.
#USAGE flag "--meta <meta>" var=#true default=""Confirmed with a small So the practical pattern is: if a task reads I'm closing this as resolved from our side. A possible upstream doc improvement would be to call out this inheritance behavior in the |
Uh oh!
There was an error while loading. Please reload this page.
Summary
File tasks that use
#USAGEspecs appear to inherit staleusage_*environment variables from the parent process when the corresponding optional arg/flag is omitted.This surprised me because the generated
usage_*variables look task-local, but an ambientusage_modelcan be mistaken for a flag supplied to the current invocation.Reproduction
Observed output:
Expected behavior
For omitted optional args/flags, I expected mise/usage to either unset the generated variable or set it to empty for the task invocation. In the repro above, I expected:
or possibly:
but not the inherited parent value.
Why this matters
This can cause nested
mise runinvocations to accidentally treat a parent task'susage_*value as input to the child task.A concrete case: a task wants
--modelto be explicit for the current invocation. If it checksusage_model, an inheritedusage_modelmakesmise run child-task ...look as though--modelwas provided, even when it was not.required=#truedoes appear to enforce actual CLI presence despite an inherited variable, so this is mostly a problem for optional or conditionally-required args/flags.Question
Is this expected behavior? If not, would you be open to clearing/generated-overriding all
usage_*variables for the task before applying parsed values?If it is expected, is there a recommended way for a task to distinguish "flag omitted in this invocation" from "ambient
usage_*value inherited from a parent task" without scanning argv manually?Environment
mise doctorstarts with:All reactions