Skip to content
This repository was archived by the owner on Jan 2, 2026. It is now read-only.

Commit d45d187

Browse files
author
Alexis Bouchez
committed
fix(errors): don't show usage systemtically when an error occurs
1 parent 660f4ac commit d45d187

12 files changed

Lines changed: 70 additions & 26 deletions

File tree

commands/deploy.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/valyentdev/cli/config"
1313
"github.com/valyentdev/cli/http"
1414
"github.com/valyentdev/cli/pkg/env"
15+
"github.com/valyentdev/cli/pkg/exit"
1516
"github.com/valyentdev/cli/tui"
1617
"github.com/valyentdev/valyent.go"
1718
)
@@ -20,8 +21,10 @@ func newDeployCmd() *cobra.Command {
2021
deployCmd := &cobra.Command{
2122
Use: "deploy",
2223
Short: "Deploy your project to Valyent",
23-
RunE: func(cmd *cobra.Command, args []string) error {
24-
return runDeployCmd()
24+
Run: func(cmd *cobra.Command, args []string) {
25+
if err := runDeployCmd(); err != nil {
26+
exit.WithError(err)
27+
}
2528
},
2629
}
2730

commands/env/list.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,39 @@ func newListEnvCmd() *cobra.Command {
1919
return err
2020
}
2121

22-
return runListEnvCmd(fleetID)
22+
if err := runListEnvCmd(fleetID); err != nil {
23+
exit.WithError(err)
24+
}
25+
26+
return nil
2327
},
2428
}
2529
listEnvCmd.Flags().StringP("fleet", "f", "", "Fleet's identifier (optional)")
2630

2731
return listEnvCmd
2832
}
2933

30-
func runListEnvCmd(fleetID string) (err error) {
34+
func runListEnvCmd(fleetID string) error {
3135
namespace, err := config.RetrieveNamespace()
3236
if err != nil {
33-
exit.WithError(err)
37+
return err
3438
}
3539

3640
if fleetID == "" {
3741
fleetID, err = tui.SelectFleet()
3842
if err != nil {
39-
exit.WithError(err)
43+
return err
4044
}
4145
}
4246

4347
client, err := http.NewClient()
4448
if err != nil {
45-
exit.WithError(err)
49+
return err
4650
}
4751

4852
envs, err := client.GetEnvironmentVariables(namespace, fleetID)
4953
if err != nil {
50-
exit.WithError(err)
54+
return err
5155
}
5256

5357
tui.ShowTable(

commands/env/load.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ func newLoadEnvCmd() *cobra.Command {
2424
return err
2525
}
2626

27-
return runLoadEnvCmd(fleetID, args)
27+
if err := runLoadEnvCmd(fleetID, args); err != nil {
28+
exit.WithError(err)
29+
}
30+
31+
return nil
2832
},
2933
}
3034
envLoadCmd.Flags().StringP("fleet", "f", "", "Fleet's identifier (optional)")
@@ -35,13 +39,13 @@ func newLoadEnvCmd() *cobra.Command {
3539
func runLoadEnvCmd(fleetID string, args []string) (err error) {
3640
namespace, err := config.RetrieveNamespace()
3741
if err != nil {
38-
exit.WithError(err)
42+
return err
3943
}
4044

4145
if fleetID == "" {
4246
fleetID, err = tui.SelectFleet()
4347
if err != nil {
44-
exit.WithError(err)
48+
return err
4549
}
4650
}
4751

commands/gateways/delete.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/charmbracelet/huh"
77
"github.com/spf13/cobra"
88
"github.com/valyentdev/cli/http"
9+
"github.com/valyentdev/cli/pkg/exit"
910
"github.com/valyentdev/cli/tui"
1011
)
1112

@@ -22,7 +23,10 @@ func newDeleteGatewayCmd() *cobra.Command {
2223
if err != nil {
2324
return err
2425
}
25-
return runDeleteGatewayCmd(gatewayID, confirmed)
26+
if err := runDeleteGatewayCmd(gatewayID, confirmed); err != nil {
27+
exit.WithError(err)
28+
}
29+
return nil
2630
},
2731
}
2832

commands/gateways/list.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ import (
66
"github.com/spf13/cobra"
77

88
"github.com/valyentdev/cli/http"
9+
"github.com/valyentdev/cli/pkg/exit"
910
tui "github.com/valyentdev/cli/tui"
1011
)
1112

1213
func newListGatewaysCmd() *cobra.Command {
1314
listGatewaysCmd := &cobra.Command{
1415
Use: "list",
15-
RunE: func(cmd *cobra.Command, args []string) error {
16-
return runListGatewaysCmd()
16+
Run: func(cmd *cobra.Command, args []string) {
17+
if err := runListGatewaysCmd(); err != nil {
18+
exit.WithError(err)
19+
}
1720
},
1821
}
1922

commands/init.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/spf13/cobra"
88
"github.com/valyentdev/cli/auth"
99
"github.com/valyentdev/cli/config"
10+
"github.com/valyentdev/cli/pkg/exit"
1011
"github.com/valyentdev/cli/tui"
1112
)
1213

@@ -19,7 +20,11 @@ func newInitCmd() *cobra.Command {
1920
if err != nil {
2021
return err
2122
}
22-
return runInitCmd(fleetID)
23+
if err := runInitCmd(fleetID); err != nil {
24+
exit.WithError(err)
25+
}
26+
27+
return nil
2328
},
2429
}
2530

commands/machines/create.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/spf13/cobra"
1010
"github.com/valyentdev/cli/http"
11+
"github.com/valyentdev/cli/pkg/exit"
1112
"github.com/valyentdev/cli/tui"
1213
"github.com/valyentdev/ravel/api"
1314
)
@@ -20,7 +21,12 @@ func newCreateMachineCmd() *cobra.Command {
2021
if err != nil {
2122
return err
2223
}
23-
return runCreateMachineCmd(jsonFilePath)
24+
25+
if err := runCreateMachineCmd(jsonFilePath); err != nil {
26+
exit.WithError(err)
27+
}
28+
29+
return nil
2430
},
2531
}
2632

commands/machines/events.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ package machines
22

33
import (
44
"github.com/spf13/cobra"
5+
"github.com/valyentdev/cli/pkg/exit"
56
"github.com/valyentdev/cli/tui"
67
)
78

89
func newListMachineEventsCmd() *cobra.Command {
910
listGatewaysCmd := &cobra.Command{
1011
Use: "events",
11-
RunE: func(cmd *cobra.Command, args []string) error {
12-
return runListMachineEventsCmd()
12+
Run: func(cmd *cobra.Command, args []string) {
13+
if err := runListMachineEventsCmd(); err != nil {
14+
exit.WithError(err)
15+
}
1316
},
1417
}
1518

commands/machines/logs.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/spf13/cobra"
77
"github.com/valyentdev/cli/http"
8+
"github.com/valyentdev/cli/pkg/exit"
89
"github.com/valyentdev/cli/pkg/logs"
910
"github.com/valyentdev/cli/tui"
1011
"github.com/valyentdev/valyent.go"
@@ -16,8 +17,10 @@ func newLogsCmd() *cobra.Command {
1617
logsCmd := &cobra.Command{
1718
Use: "logs",
1819
Short: "Display logs from a machine",
19-
RunE: func(cmd *cobra.Command, args []string) error {
20-
return runLogsCmd(follow)
20+
Run: func(cmd *cobra.Command, args []string) {
21+
if err := runLogsCmd(follow); err != nil {
22+
exit.WithError(err)
23+
}
2124
},
2225
}
2326

commands/machines/start.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ import (
66
"github.com/charmbracelet/huh"
77
"github.com/spf13/cobra"
88
"github.com/valyentdev/cli/http"
9+
"github.com/valyentdev/cli/pkg/exit"
910
"github.com/valyentdev/cli/tui"
1011
)
1112

1213
func newStartMachineCmd() *cobra.Command {
1314
logsCmd := &cobra.Command{
1415
Use: "start",
15-
RunE: func(cmd *cobra.Command, args []string) error {
16-
return runStartMachineCmd()
16+
Run: func(cmd *cobra.Command, args []string) {
17+
if err := runStartMachineCmd(); err != nil {
18+
exit.WithError(err)
19+
}
1720
},
1821
}
1922

0 commit comments

Comments
 (0)