Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow not waiting for actions #843

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/cmd/config/helptext/preferences.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.<resource> │ Default sorting for │ string list │ sort.<resource> │ HCLOUD_SORT_<RESOURCE> │ │
│ │ resource │ │ │ │ │
└──────────────────┴──────────────────────┴─────────────┴──────────────────┴─────────────────────────┴─────────────────┘
15 changes: 15 additions & 0 deletions internal/state/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,25 @@ import (
)

func (c *state) WaitForActions(cmd *cobra.Command, ctx context.Context, actions ...*hcloud.Action) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have "composite" commands in the CLI, where we wait for some actions and then make more API calls? These could fail if we do not wait for the initial actions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for example when enabling protection after resource creation. How about we add a function like MustWaitForActions which doesn't include the wait option logic and then make WaitForActions a wrapper of that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds fine to me.

We should also look at these cases and decide if its really necessary to wait for the running actions or the next call is independent and can still be made. (ie. is it necessary for the server to start before enabling the protection?)

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 {
ui.SkipActionWaitMessage(action)
}
return nil
apricote marked this conversation as resolved.
Show resolved Hide resolved
}

if quiet {
return c.Client().Action().WaitFor(ctx, actions...)
}
Expand Down
8 changes: 8 additions & 0 deletions internal/state/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions internal/ui/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down