From 6b310970beca7256d36b10c7cedb8e35a640c319 Mon Sep 17 00:00:00 2001 From: phm07 <22707808+phm07@users.noreply.github.com> Date: Wed, 14 Aug 2024 10:21:41 +0200 Subject: [PATCH 1/7] feat: allow not waiting for actions --- internal/state/actions.go | 4 ++++ internal/state/config/options.go | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/internal/state/actions.go b/internal/state/actions.go index 323106e5..0bbae8db 100644 --- a/internal/state/actions.go +++ b/internal/state/actions.go @@ -14,6 +14,10 @@ import ( ) func (c *state) WaitForActions(cmd *cobra.Command, ctx context.Context, actions ...*hcloud.Action) error { + if noWait, _ := cmd.Flags().GetBool("no-wait"); noWait { + return nil + } + quiet, err := config.OptionQuiet.Get(c.Config()) if err != nil { return err diff --git a/internal/state/config/options.go b/internal/state/config/options.go index 2e593c8e..f35e701e 100644 --- a/internal/state/config/options.go +++ b/internal/state/config/options.go @@ -138,6 +138,14 @@ var ( nil, ) + OptionNoWait = newOpt( + "no-wait", + "If true, do not wait for actions to complete", + false, + DefaultPreferenceFlags, + nil, + ) + OptionDefaultSSHKeys = newOpt( "default-ssh-keys", "Default SSH keys for new servers", From 62ee8462018eca8671d5136d985732f6a44b1a8d Mon Sep 17 00:00:00 2001 From: phm07 <22707808+phm07@users.noreply.github.com> Date: Wed, 14 Aug 2024 10:24:18 +0200 Subject: [PATCH 2/7] generate help text --- internal/cmd/config/helptext/preferences.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/cmd/config/helptext/preferences.txt b/internal/cmd/config/helptext/preferences.txt index 7049798a..7810b38b 100644 --- a/internal/cmd/config/helptext/preferences.txt +++ b/internal/cmd/config/helptext/preferences.txt @@ -12,6 +12,10 @@ │ endpoint │ Hetzner Cloud API │ string │ endpoint │ HCLOUD_ENDPOINT │ --endpoint │ │ │ endpoint │ │ │ │ │ ├──────────────────┼──────────────────────┼─────────────┼──────────────────┼─────────────────────────┼─────────────────┤ +│ no-wait │ If true, do not wait │ boolean │ no_wait │ HCLOUD_NO_WAIT │ --no-wait │ +│ │ for actions to │ │ │ │ │ +│ │ complete │ │ │ │ │ +├──────────────────┼──────────────────────┼─────────────┼──────────────────┼─────────────────────────┼─────────────────┤ │ poll-interval │ Interval at which to │ duration │ poll_interval │ HCLOUD_POLL_INTERVAL │ --poll-interval │ │ │ poll information, │ │ │ │ │ │ │ for example action │ │ │ │ │ From 58ab0daa34f4e605143654587147fe1baf44c51d Mon Sep 17 00:00:00 2001 From: phm07 <22707808+phm07@users.noreply.github.com> Date: Mon, 19 Aug 2024 10:55:57 +0200 Subject: [PATCH 3/7] rename no-wait to wait --- internal/cmd/config/helptext/preferences.txt | 8 ++++---- internal/state/actions.go | 2 +- internal/state/config/options.go | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/internal/cmd/config/helptext/preferences.txt b/internal/cmd/config/helptext/preferences.txt index 7810b38b..1aa749f5 100644 --- a/internal/cmd/config/helptext/preferences.txt +++ b/internal/cmd/config/helptext/preferences.txt @@ -12,10 +12,6 @@ │ endpoint │ Hetzner Cloud API │ string │ endpoint │ HCLOUD_ENDPOINT │ --endpoint │ │ │ endpoint │ │ │ │ │ ├──────────────────┼──────────────────────┼─────────────┼──────────────────┼─────────────────────────┼─────────────────┤ -│ no-wait │ If true, do not wait │ boolean │ no_wait │ HCLOUD_NO_WAIT │ --no-wait │ -│ │ for actions to │ │ │ │ │ -│ │ complete │ │ │ │ │ -├──────────────────┼──────────────────────┼─────────────┼──────────────────┼─────────────────────────┼─────────────────┤ │ poll-interval │ Interval at which to │ duration │ poll_interval │ HCLOUD_POLL_INTERVAL │ --poll-interval │ │ │ poll information, │ │ │ │ │ │ │ for example action │ │ │ │ │ @@ -24,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 0bbae8db..f40398a6 100644 --- a/internal/state/actions.go +++ b/internal/state/actions.go @@ -14,7 +14,7 @@ import ( ) func (c *state) WaitForActions(cmd *cobra.Command, ctx context.Context, actions ...*hcloud.Action) error { - if noWait, _ := cmd.Flags().GetBool("no-wait"); noWait { + if wait, _ := config.OptionWait.Get(c.Config()); !wait { return nil } diff --git a/internal/state/config/options.go b/internal/state/config/options.go index f35e701e..dc52ddc8 100644 --- a/internal/state/config/options.go +++ b/internal/state/config/options.go @@ -138,10 +138,10 @@ var ( nil, ) - OptionNoWait = newOpt( - "no-wait", - "If true, do not wait for actions to complete", - false, + OptionWait = newOpt( + "wait", + "If false, do not wait for actions to complete", + true, DefaultPreferenceFlags, nil, ) From c6681f4b896552020bd1dd5d5eeb5af62fe8cc2e Mon Sep 17 00:00:00 2001 From: phm07 <22707808+phm07@users.noreply.github.com> Date: Mon, 19 Aug 2024 11:07:45 +0200 Subject: [PATCH 4/7] add error handling --- internal/state/actions.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/state/actions.go b/internal/state/actions.go index f40398a6..f142256b 100644 --- a/internal/state/actions.go +++ b/internal/state/actions.go @@ -14,7 +14,11 @@ import ( ) func (c *state) WaitForActions(cmd *cobra.Command, ctx context.Context, actions ...*hcloud.Action) error { - if wait, _ := config.OptionWait.Get(c.Config()); !wait { + wait, err := config.OptionWait.Get(c.Config()) + if err != nil { + return err + } + if !wait { return nil } From 7fe090400742dcfd1b253586cf869062c0c64b44 Mon Sep 17 00:00:00 2001 From: phm07 <22707808+phm07@users.noreply.github.com> Date: Mon, 19 Aug 2024 11:24:28 +0200 Subject: [PATCH 5/7] print message when skipping wait --- internal/state/actions.go | 3 +++ internal/ui/actions.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/internal/state/actions.go b/internal/state/actions.go index f142256b..fb064042 100644 --- a/internal/state/actions.go +++ b/internal/state/actions.go @@ -19,6 +19,9 @@ func (c *state) WaitForActions(cmd *cobra.Command, ctx context.Context, actions return err } if !wait { + for _, action := range actions { + ui.SkipActionWaitMessage(action) + } return nil } 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. // From d2abdeb0e133f2f714e40b42bc6663085a214ad3 Mon Sep 17 00:00:00 2001 From: phm07 <22707808+phm07@users.noreply.github.com> Date: Mon, 19 Aug 2024 11:27:33 +0200 Subject: [PATCH 6/7] do not print messages when quiet is set --- internal/state/actions.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/state/actions.go b/internal/state/actions.go index fb064042..aebd2c5c 100644 --- a/internal/state/actions.go +++ b/internal/state/actions.go @@ -18,17 +18,21 @@ func (c *state) WaitForActions(cmd *cobra.Command, ctx context.Context, actions 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 } - quiet, err := config.OptionQuiet.Get(c.Config()) - if err != nil { - return err - } if quiet { return c.Client().Action().WaitFor(ctx, actions...) } From 1b3d7dd1ad95ab80e19ae428179a68e91da731d1 Mon Sep 17 00:00:00 2001 From: phm07 <22707808+phm07@users.noreply.github.com> Date: Mon, 19 Aug 2024 11:30:46 +0200 Subject: [PATCH 7/7] fix --- internal/state/actions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/state/actions.go b/internal/state/actions.go index aebd2c5c..bf3a4f99 100644 --- a/internal/state/actions.go +++ b/internal/state/actions.go @@ -28,7 +28,7 @@ func (c *state) WaitForActions(cmd *cobra.Command, ctx context.Context, actions return nil } for _, action := range actions { - ui.SkipActionWaitMessage(action) + cmd.Println(ui.SkipActionWaitMessage(action)) } return nil }