diff --git a/cmd/dbc/completions/dbc.bash b/cmd/dbc/completions/dbc.bash index 543f8b07..936174f8 100644 --- a/cmd/dbc/completions/dbc.bash +++ b/cmd/dbc/completions/dbc.bash @@ -5,7 +5,7 @@ _dbc() { _init_completion || return local subcommands="install uninstall init add sync search info remove completion" - local global_opts="--help -h --version" + local global_opts="--help -h --version --quiet -q" # If we're completing the first argument (subcommand) if [[ $cword -eq 1 ]]; then diff --git a/cmd/dbc/completions/dbc.fish b/cmd/dbc/completions/dbc.fish index 36562283..91b4a224 100644 --- a/cmd/dbc/completions/dbc.fish +++ b/cmd/dbc/completions/dbc.fish @@ -25,6 +25,7 @@ end complete -c dbc -n '__fish_dbc_needs_command' -l help -d 'Show help' complete -c dbc -n '__fish_dbc_needs_command' -s h -d 'Show help' complete -c dbc -n '__fish_dbc_needs_command' -l version -d 'Show version' +complete -c dbc -n '__fish_dbc_needs_command' -l quiet -s q -d 'Suppress all output' # Subcommands complete -f -c dbc -n '__fish_dbc_needs_command' -a 'install' -d 'Install a driver' diff --git a/cmd/dbc/completions/dbc.zsh b/cmd/dbc/completions/dbc.zsh index 95a20355..e8418d3d 100644 --- a/cmd/dbc/completions/dbc.zsh +++ b/cmd/dbc/completions/dbc.zsh @@ -24,7 +24,9 @@ function _dbc { 'completion[Generate shell completions]' \ '--help[Show help]' \ '-h[Show help]' \ - '--version[Show version]' + '--version[Show version]' \ + '--quiet[Suppress all output]' \ + '-q[Suppress all output]' ;; args) case $line[1] in diff --git a/cmd/dbc/main.go b/cmd/dbc/main.go index bb8abb90..683dd033 100644 --- a/cmd/dbc/main.go +++ b/cmd/dbc/main.go @@ -135,6 +135,7 @@ type cmds struct { Docs *DocsCmd `arg:"subcommand" help:"Open driver documentation in a web browser"` Remove *RemoveCmd `arg:"subcommand" help:"Remove a driver from the driver list"` Completion *completions.Cmd `arg:"subcommand" help:"-"` + Quiet bool `arg:"-q,--quiet" help:"Suppress all output"` } func (cmds) Version() string { @@ -197,17 +198,22 @@ func main() { if !isatty.IsTerminal(os.Stdout.Fd()) { prog = tea.NewProgram(m, tea.WithoutRenderer(), tea.WithInput(nil)) + } else if args.Quiet { + // Quiet still prints stderr as GNU standard is to supress "usual" output + prog = tea.NewProgram(m, tea.WithoutRenderer(), tea.WithInput(nil), tea.WithOutput(os.Stderr)) } else { prog = tea.NewProgram(m) } if m, err = prog.Run(); err != nil { - fmt.Println("Error running program:", err) + fmt.Fprintln(os.Stderr, "Error running program:", err) os.Exit(1) } - if fo, ok := m.(HasFinalOutput); ok { - fmt.Print(fo.FinalOutput()) + if !args.Quiet { + if fo, ok := m.(HasFinalOutput); ok { + fmt.Print(fo.FinalOutput()) + } } if h, ok := m.(HasStatus); ok { diff --git a/docs/reference/cli.md b/docs/reference/cli.md index 158e3cce..11371835 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -70,6 +70,10 @@ $ dbc search [FILTER] : Enable verbose output +`--quiet`, `-q` + +: Suppress all output + ## install Install a driver. @@ -98,6 +102,10 @@ $ dbc install [OPTIONS] : Allow installation of drivers without a signature file +`--quiet`, `-q` + +: Suppress all output + ## uninstall Uninstall a driver. @@ -120,6 +128,10 @@ $ dbc uninstall [OPTIONS] : The configuration level to uninstall the driver from (`user`, or `system`). See [Config Level](config_level.md). +`--quiet`, `-q` + +: Suppress all output + ## init Create a [driver list](../concepts/driver_list.md) file. @@ -136,6 +148,12 @@ $ dbc init [PATH] : Optional. A path to create a [driver list](../concepts/driver_list.md) under. Defaults to the current working directory. +

Options

+ +`--quiet`, `-q` + +: Suppress all output + ## add Add a driver to a current [driver list](../concepts/driver_list.md). @@ -158,6 +176,10 @@ $ dbc add : Driver list to add to [default: ./dbc.toml] +`--quiet`, `-q` + +: Suppress all output + ## remove Remove a driver from the current [driver list](../concepts/driver_list.md). @@ -180,6 +202,10 @@ $ dbc remove : Driver list to remove from [default: ./dbc.toml] +`--quiet`, `-q` + +: Suppress all output + ## sync Install drivers from a [driver list](../concepts/driver_list.md). @@ -207,6 +233,10 @@ dbc sync --file dbc.toml : Allow installation of drivers without a signature file +`--quiet`, `-q` + +: Suppress all output + ## info Get information about a driver. Shows information about the latest version of the driver with the given name. @@ -223,6 +253,12 @@ $ dbc info : Name of the driver to get information for. +

Options

+ +`--quiet`, `-q` + +: Suppress all output + ## docs Open driver documentation in a web browser. If no driver is specified, opens the general dbc documentation. If a driver name is provided, opens the documentation for that specific driver. @@ -245,3 +281,7 @@ $ dbc docs `--no-open` : Print the documentation URL instead of opening it in a browser + +`--quiet`, `-q` + +: Suppress all output