Global handling of re-used flags in clap

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?

This was perfectly answered in a github discussion! If anyone else comes across this thread, I got the exactly was I was looking for with Arg::global

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.