Shared options / custom help text for every subcommand #60
pawamoy
started this conversation in
Show and tell
Replies: 1 comment 2 replies
-
For what it's worth, With that said, this pattern certainly makes sense generally. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
To customize the description of the
--help
flag for each of my subcommand, I used this pattern:Decorating commands with
dataclass
is necessary, because otherwise the base class (HelpOption
) does nothing through inheritance, and by the time@cappa.command
picks it up it's too late.The
kw_only=True
option is also necessary, because the order of attributes matter in a dataclass, and attributes without a default value cannot appear after attributes with a default value, unless they're all keyword-only attributes.This pattern can be used more generally to share options between commands. Here I'm just using it to customize the description of
--help
once for all subcommands.Beta Was this translation helpful? Give feedback.
All reactions