Default Parameter
The default values of Parameter
for an app can be configured via App.default_parameter
.
For example, to disable the negative
flag feature across your entire app:
from cyclopts import App, Parameter
app = App(default_parameter=Parameter(negative=()))
@app.command
def foo(*, flag: bool):
pass
app()
Consequently, --no-flag
is no longer an allowed flag:
$ my-script foo --help
Usage: my-script foo [ARGS] [OPTIONS]
╭─ Parameters ──────────────────────────────────────────────────╮
│ * --flag [required] │
╰───────────────────────────────────────────────────────────────╯
Explicitly annotating the parameter with negative
overrides this configuration and works as expected:
from cyclopts import App, Parameter
from typing import Annotated
app = App(default_parameter=Parameter(negative=()))
@app.command
def foo(*, flag: Annotated[bool, Parameter(negative="--anti-flag")]):
pass
app()
$ my-script foo --help
Usage: my-script foo [ARGS] [OPTIONS]
╭─ Parameters ──────────────────────────────────────────────────╮
│ * --flag --anti-flag [required] │
╰───────────────────────────────────────────────────────────────╯
Resolution Order
When resolving what the Parameter
values for an individual function parameter should be, explicitly set attributes of higher priority Parameter
s override lower priority Parameter
s. The resolution order is as follows:
Highest Priority: Parameter-annotated command function signature
Annotated[..., Parameter()]
.Group.default_parameter
that the parameter belongs to.App.default_parameter
of the app that registered the command.Group.default_parameter
of the app that the function belongs to.Lowest Priority: (2-4) recursively of the parenting app call-chain.
Any of Parameter's fields can be set to None to revert back to the true-original Cyclopts default.