-
Notifications
You must be signed in to change notification settings - Fork 325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Passing state from root to subcommands #632
Comments
If you nest @main
struct RootCommand : AsyncParsableCommand<Raise3DAPI> {
...
struct Monitor : AsyncParsableCommand<Raise3DAPI> {
...
@OptionGroup
var root: RootCommand
mutating func run() async throws
// Access `root.addr` and `root.password`...
}
} But you can't just make Maybe you can make |
A similar problem I'm having, although not related to passing state, is that if my Root command is a container for subcommands, I don't have a chance to execute any code at startup. For example this doesn't let me setup a logging system since the only code that runs is from the subcommand. |
I've been able to do this via the |
Working on a tool with a handful of subcommands, I find myself wanting to handle common work in the root command, and then pass some state to the subcommand. I’m not sure what might be possible, but something like this is what I’d like to be able to do:
This lets subcommands be a little cleaner, because they don't have to redundantly declare the global options, and all the common work is done in the parent command. The desired state is generic.
The text was updated successfully, but these errors were encountered: