From d675ae7c03c0e6b557e283c67a8e957fd5725954 Mon Sep 17 00:00:00 2001 From: pauhull Date: Tue, 2 Jan 2024 13:57:07 +0100 Subject: [PATCH] feat: add global --quiet flag to hide progress indicators Closes #644 --- internal/cli/root.go | 1 + internal/state/helpers.go | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/internal/cli/root.go b/internal/cli/root.go index b3ca29c3..de73e652 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -63,6 +63,7 @@ func NewRootCommand(state *state.State, client hcapi2.Client) *cobra.Command { primaryip.NewCommand(state, client), ) cmd.PersistentFlags().Duration("poll-interval", 500*time.Millisecond, "Interval at which to poll information, for example action progress") + cmd.PersistentFlags().Bool("quiet", false, "Hide progress indicators") cmd.SetOut(os.Stdout) return cmd } diff --git a/internal/state/helpers.go b/internal/state/helpers.go index a08eedfb..73f5b405 100644 --- a/internal/state/helpers.go +++ b/internal/state/helpers.go @@ -66,6 +66,10 @@ func (c *State) ActionProgress(cmd *cobra.Command, ctx context.Context, action * func (c *State) ActionsProgresses(cmd *cobra.Command, ctx context.Context, actions []*hcloud.Action) error { progressCh, errCh := c.Client().Action.WatchOverallProgress(ctx, actions) + if quiet, _ := cmd.Flags().GetBool("quiet"); quiet { + return <-errCh + } + if StdoutIsTerminal() { progress := pb.New(100) progress.SetMaxWidth(50) // width of progress bar is too large by default @@ -131,6 +135,10 @@ func DisplayProgressCircle(cmd *cobra.Command, errCh <-chan error, waitingFor st ellipsis = " ... " ) + if quiet, _ := cmd.Flags().GetBool("quiet"); quiet { + return <-errCh + } + if StdoutIsTerminal() { _, _ = fmt.Fprintln(os.Stderr, waitingFor)