I'm working on a large binary that uses clap
, and want to have a centralized handler for flags that are common across multiple sub-commands. For example, there is a flag called --no-prompt
, and each sub-command that exposes the flag has code similar to:
if no_prompt {
interaction::set_context(InteractiveContext::NotInteractive)
} else {
interaction::set_context(InteractiveContext::Terminal)
}
Is it possible to declare at the root-level (main.rs
) a shared way to handle this for all subcommands? Or would this be adding too much indirection and it would just be easier to just duplicate the logic for every subcommand?