Skip to content

Commit 9d5ba51

Browse files
thcyronnikolak
authored andcommitted
Show action progress and check status everywhere (#104)
1 parent 460e2b8 commit 9d5ba51

16 files changed

Lines changed: 41 additions & 81 deletions

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## master
44

5+
* Show progress for every action
56
* Show datacenter in `server list` and `server describe`
67

78
## v1.3.1

cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func (c *CLI) Terminal() bool {
127127
}
128128

129129
func (c *CLI) ActionProgress(ctx context.Context, action *hcloud.Action) error {
130-
errCh, progressCh := waitAction(ctx, c.Client(), action)
130+
progressCh, errCh := c.Client().Action.WatchProgress(ctx, action)
131131

132132
if c.Terminal() {
133133
progress := uiprogress.New()

floatingip_assign.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ func runFloatingIPAssign(cli *CLI, cmd *cobra.Command, args []string) error {
4343
if err != nil {
4444
return err
4545
}
46-
errCh, _ := waitAction(cli.Context, cli.Client(), action)
47-
if err := <-errCh; err != nil {
46+
47+
if err := cli.ActionProgress(cli.Context, action); err != nil {
4848
return err
4949
}
50+
5051
fmt.Printf("Floating IP %d assigned to server %s\n", floatingIP.ID, server.Name)
5152
return nil
5253
}

floatingip_unassign.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ func runFloatingIPUnassign(cli *CLI, cmd *cobra.Command, args []string) error {
3333
if err != nil {
3434
return err
3535
}
36-
errCh, _ := waitAction(cli.Context, cli.Client(), action)
37-
if err := <-errCh; err != nil {
36+
37+
if err := cli.ActionProgress(cli.Context, action); err != nil {
3838
return err
3939
}
40+
4041
fmt.Printf("Floating IP %d unassigned\n", floatingIP.ID)
4142
return nil
4243
}

server_disable_backup.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ func runServerDisableBackup(cli *CLI, cmd *cobra.Command, args []string) error {
3333
if err != nil {
3434
return err
3535
}
36-
errCh, _ := waitAction(cli.Context, cli.Client(), action)
37-
if err := <-errCh; err != nil {
36+
37+
if err := cli.ActionProgress(cli.Context, action); err != nil {
3838
return err
3939
}
40+
4041
fmt.Printf("Backup disabled for server %s\n", server.Name)
4142
return nil
4243
}

server_disable_rescue.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ func runServerDisableRescue(cli *CLI, cmd *cobra.Command, args []string) error {
3333
if err != nil {
3434
return err
3535
}
36-
errCh, _ := waitAction(cli.Context, cli.Client(), action)
37-
if err := <-errCh; err != nil {
36+
37+
if err := cli.ActionProgress(cli.Context, action); err != nil {
3838
return err
3939
}
40+
4041
fmt.Printf("Rescue disabled for server %s\n", server.Name)
4142
return nil
4243
}

server_enable_backup.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ func runServerEnableBackup(cli *CLI, cmd *cobra.Command, args []string) error {
4040
if err != nil {
4141
return err
4242
}
43-
errCh, _ := waitAction(cli.Context, cli.Client(), action)
44-
if err := <-errCh; err != nil {
43+
44+
if err := cli.ActionProgress(cli.Context, action); err != nil {
4545
return err
4646
}
47+
4748
fmt.Printf("Backup enabled for server %s\n", server.Name)
4849
return nil
4950
}

server_enable_rescue.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ func runServerEnableRescue(cli *CLI, cmd *cobra.Command, args []string) error {
6161
if err != nil {
6262
return err
6363
}
64-
errCh, _ := waitAction(cli.Context, cli.Client(), result.Action)
65-
if err := <-errCh; err != nil {
64+
65+
if err := cli.ActionProgress(cli.Context, result.Action); err != nil {
6666
return err
6767
}
68+
6869
fmt.Printf("Rescue enabled for server %s with root password: %s\n", server.Name, result.RootPassword)
6970
return nil
7071
}

server_poweroff.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ func runServerPoweroff(cli *CLI, cmd *cobra.Command, args []string) error {
3333
if err != nil {
3434
return err
3535
}
36-
errCh, _ := waitAction(cli.Context, cli.Client(), action)
37-
if err := <-errCh; err != nil {
36+
37+
if err := cli.ActionProgress(cli.Context, action); err != nil {
3838
return err
3939
}
40+
4041
fmt.Printf("Server %s stopped\n", server.Name)
4142
return nil
4243
}

server_poweron.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ func runServerPoweron(cli *CLI, cmd *cobra.Command, args []string) error {
3333
if err != nil {
3434
return err
3535
}
36-
errCh, _ := waitAction(cli.Context, cli.Client(), action)
37-
if err := <-errCh; err != nil {
36+
37+
if err := cli.ActionProgress(cli.Context, action); err != nil {
3838
return err
3939
}
40+
4041
fmt.Printf("Server %s started\n", server.Name)
4142
return nil
4243
}

0 commit comments

Comments
 (0)