diff --git a/internal/cmd/config/helptext/preferences.txt b/internal/cmd/config/helptext/preferences.txt index 7049798a..1aa749f5 100644 --- a/internal/cmd/config/helptext/preferences.txt +++ b/internal/cmd/config/helptext/preferences.txt @@ -20,6 +20,10 @@ │ quiet │ If true, only print │ boolean │ quiet │ HCLOUD_QUIET │ --quiet │ │ │ error messages │ │ │ │ │ ├──────────────────┼──────────────────────┼─────────────┼──────────────────┼─────────────────────────┼─────────────────┤ +│ wait │ If false, do not │ boolean │ wait │ HCLOUD_WAIT │ --wait │ +│ │ wait for actions to │ │ │ │ │ +│ │ complete │ │ │ │ │ +├──────────────────┼──────────────────────┼─────────────┼──────────────────┼─────────────────────────┼─────────────────┤ │ sort. │ Default sorting for │ string list │ sort. │ HCLOUD_SORT_ │ │ │ │ resource │ │ │ │ │ └──────────────────┴──────────────────────┴─────────────┴──────────────────┴─────────────────────────┴─────────────────┘ diff --git a/internal/state/actions.go b/internal/state/actions.go index 323106e5..bf3a4f99 100644 --- a/internal/state/actions.go +++ b/internal/state/actions.go @@ -14,10 +14,25 @@ import ( ) func (c *state) WaitForActions(cmd *cobra.Command, ctx context.Context, actions ...*hcloud.Action) error { + wait, err := config.OptionWait.Get(c.Config()) + if err != nil { + return err + } quiet, err := config.OptionQuiet.Get(c.Config()) if err != nil { return err } + + if !wait { + if quiet { + return nil + } + for _, action := range actions { + cmd.Println(ui.SkipActionWaitMessage(action)) + } + return nil + } + if quiet { return c.Client().Action().WaitFor(ctx, actions...) } diff --git a/internal/state/config/options.go b/internal/state/config/options.go index 2e593c8e..dc52ddc8 100644 --- a/internal/state/config/options.go +++ b/internal/state/config/options.go @@ -138,6 +138,14 @@ var ( nil, ) + OptionWait = newOpt( + "wait", + "If false, do not wait for actions to complete", + true, + DefaultPreferenceFlags, + nil, + ) + OptionDefaultSSHKeys = newOpt( "default-ssh-keys", "Default SSH keys for new servers", diff --git a/internal/ui/actions.go b/internal/ui/actions.go index 6620c391..e01b288a 100644 --- a/internal/ui/actions.go +++ b/internal/ui/actions.go @@ -13,6 +13,10 @@ func ActionMessage(action *hcloud.Action) string { return fmt.Sprintf("Waiting for %s", color.New(color.Bold).Sprint(action.Command)) } +func SkipActionWaitMessage(action *hcloud.Action) string { + return fmt.Sprintf("Skipping waiting for %s", color.New(color.Bold).Sprint(action.Command)) +} + // FakeActionMessage returns the initial value with a unused color to grow the string // size. //