Skip to content

Commit

Permalink
feat: add global --quiet flag to hide progress indicators
Browse files Browse the repository at this point in the history
Closes #644
  • Loading branch information
phm07 committed Jan 2, 2024
1 parent f636b5e commit a7d9a0c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 8 additions & 0 deletions internal/state/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit a7d9a0c

Please sign in to comment.