package diary // helpOnly reports whether args, a binary's command line without the // program name, only ask for help: before "--" they hold --help or a // single-dash cluster that reaches h. It is a tolerant pre-scan of the raw // arguments, made before plugins boot, and reads them the way // bonfire.PeekGlobals does: it stops at "--", skips the value of --env and // reads a single-dash cluster letter by letter, stopping at the first // letter that is not a global shorthand (v, q, n, h). It never fails and // cannot tell a passthrough command (whose --help reaches its Run) from // another, so " --help" counts; the root's OnGlobals hook // (ApplyGlobals) restores the console levels before that command runs. func helpOnly(args []string) bool { for i := 0; i < len(args); i++ { a := args[i] switch { case a == "--": return false case a == "--env": i++ case a == "--help": return true case len(a) >= 2 && a[0] == '-' && a[1] != '-': if clusterHasHelp(a[1:]) { return true } } } return false } // clusterHasHelp reports whether a shorthand cluster (the letters after the // dash) reaches h before a letter that is not a global shorthand. func clusterHasHelp(cluster string) bool { for i := 0; i < len(cluster); i++ { switch cluster[i] { case 'h': return true case 'v', 'q', 'n': default: return false } } return false } // bootQuiet applies the help-only rule of Bootstrap and Setup: with Args // set, no -v and arguments that only ask for help, the setup is installed // with Quiet, which raises only the console channels to warn. func bootQuiet(opts Options) Options { if opts.Args != nil && opts.Verbosity == 0 && helpOnly(opts.Args) { opts.Quiet = true } return opts }