Skip to content

Commit 7a5d276

Browse files
Clean up cmd.SilenceUsage = true settings
1 parent d120e1f commit 7a5d276

4 files changed

Lines changed: 32 additions & 22 deletions

File tree

internal/tiger/cmd/config.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,14 @@ func buildConfigSetCmd() *cobra.Command {
9090
Args: cobra.ExactArgs(2),
9191
ValidArgsFunction: configOptionCompletion,
9292
RunE: func(cmd *cobra.Command, args []string) error {
93-
key, value := args[0], args[1]
94-
9593
cmd.SilenceUsage = true
9694

9795
cfg, err := config.Load()
9896
if err != nil {
9997
return fmt.Errorf("failed to load config: %w", err)
10098
}
10199

100+
key, value := args[0], args[1]
102101
if err := cfg.Set(key, value); err != nil {
103102
return fmt.Errorf("failed to set config: %w", err)
104103
}
@@ -118,15 +117,14 @@ func buildConfigUnsetCmd() *cobra.Command {
118117
Args: cobra.ExactArgs(1),
119118
ValidArgsFunction: configOptionCompletion,
120119
RunE: func(cmd *cobra.Command, args []string) error {
121-
key := args[0]
122-
123120
cmd.SilenceUsage = true
124121

125122
cfg, err := config.Load()
126123
if err != nil {
127124
return fmt.Errorf("failed to load config: %w", err)
128125
}
129126

127+
key := args[0]
130128
if err := cfg.Unset(key); err != nil {
131129
return fmt.Errorf("failed to unset config: %w", err)
132130
}

internal/tiger/cmd/db.go

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ Examples:
7777
RunE: func(cmd *cobra.Command, args []string) error {
7878
cfg, err := common.LoadConfig(cmd.Context())
7979
if err != nil {
80+
cmd.SilenceUsage = true
8081
return err
8182
}
82-
service, err := getServiceDetails(cmd, cfg, args)
83+
84+
service, err := getServiceDetailsFunc(cmd, cfg, args)
8385
if err != nil {
8486
return err
8587
}
@@ -158,13 +160,16 @@ Examples:
158160
Args: cobra.ArbitraryArgs,
159161
ValidArgsFunction: serviceIDCompletion,
160162
RunE: func(cmd *cobra.Command, args []string) error {
161-
// Separate service ID from additional psql flags
162-
serviceArgs, psqlFlags := separateServiceAndPsqlArgs(cmd, args)
163163
cfg, err := common.LoadConfig(cmd.Context())
164164
if err != nil {
165+
cmd.SilenceUsage = true
165166
return err
166167
}
167-
service, err := getServiceDetails(cmd, cfg, serviceArgs)
168+
169+
// Separate service ID from additional psql flags
170+
serviceArgs, psqlFlags := separateServiceAndPsqlArgs(cmd, args)
171+
172+
service, err := getServiceDetailsFunc(cmd, cfg, serviceArgs)
168173
if err != nil {
169174
return err
170175
}
@@ -238,9 +243,11 @@ Examples:
238243
RunE: func(cmd *cobra.Command, args []string) error {
239244
cfg, err := common.LoadConfig(cmd.Context())
240245
if err != nil {
246+
cmd.SilenceUsage = true
241247
return err
242248
}
243-
service, err := getServiceDetails(cmd, cfg, args)
249+
250+
service, err := getServiceDetailsFunc(cmd, cfg, args)
244251
if err != nil {
245252
return common.ExitWithCode(common.ExitInvalidParameters, err)
246253
}
@@ -316,8 +323,10 @@ Examples:
316323
RunE: func(cmd *cobra.Command, args []string) error {
317324
cfg, err := common.LoadConfig(cmd.Context())
318325
if err != nil {
326+
cmd.SilenceUsage = true
319327
return err
320328
}
329+
321330
service, err := getServiceDetailsFunc(cmd, cfg, args)
322331
if err != nil {
323332
return err
@@ -661,23 +670,22 @@ PostgreSQL Configuration Parameters That May Be Set:
661670
return fmt.Errorf("--name is required")
662671
}
663672

664-
cmd.SilenceUsage = true
665-
666673
cfg, err := common.LoadConfig(cmd.Context())
667674
if err != nil {
675+
cmd.SilenceUsage = true
668676
return err
669677
}
670678

671-
// Get password
672-
rolePassword, err := getPasswordForRole(passwordFlag)
679+
// Get service details
680+
service, err := getServiceDetailsFunc(cmd, cfg, args)
673681
if err != nil {
674-
return fmt.Errorf("failed to determine password: %w", err)
682+
return err
675683
}
676684

677-
// Get service details
678-
service, err := getServiceDetails(cmd, cfg, args)
685+
// Get password
686+
rolePassword, err := getPasswordForRole(passwordFlag)
679687
if err != nil {
680-
return err
688+
return fmt.Errorf("failed to determine password: %w", err)
681689
}
682690

683691
// Build connection string
@@ -761,7 +769,6 @@ func buildDbCmd() *cobra.Command {
761769

762770
// getServiceDetails is a helper that handles common service lookup logic and returns the service details
763771
func getServiceDetails(cmd *cobra.Command, cfg *common.Config, args []string) (api.Service, error) {
764-
765772
// Determine service ID
766773
serviceID, err := getServiceID(cfg.Config, args)
767774
if err != nil {

internal/tiger/cmd/service.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Examples:
7575
// Load config and API client
7676
cfg, err := common.LoadConfig(cmd.Context())
7777
if err != nil {
78+
cmd.SilenceUsage = true
7879
return err
7980
}
8081

@@ -129,14 +130,14 @@ func buildServiceListCmd() *cobra.Command {
129130
ValidArgsFunction: cobra.NoFileCompletions,
130131
PreRunE: bindFlags("output"),
131132
RunE: func(cmd *cobra.Command, args []string) error {
133+
cmd.SilenceUsage = true
134+
132135
// Load config and API client
133136
cfg, err := common.LoadConfig(cmd.Context())
134137
if err != nil {
135138
return err
136139
}
137140

138-
cmd.SilenceUsage = true
139-
140141
// Make API call to list services
141142
ctx, cancel := context.WithTimeout(cmd.Context(), 30*time.Second)
142143
defer cancel()
@@ -442,6 +443,7 @@ Examples:
442443
// Load config and API client
443444
cfg, err := common.LoadConfig(cmd.Context())
444445
if err != nil {
446+
cmd.SilenceUsage = true
445447
return err
446448
}
447449

@@ -453,7 +455,6 @@ Examples:
453455

454456
// Get password from flag or environment variable via viper
455457
password := viper.GetString("new_password")
456-
457458
if autoGenerate && password != "" {
458459
return fmt.Errorf("cannot use --auto-generate and --new-password together")
459460
}
@@ -926,6 +927,7 @@ Examples:
926927
// Load config and API client
927928
cfg, err := common.LoadConfig(cmd.Context())
928929
if err != nil {
930+
cmd.SilenceUsage = true
929931
return err
930932
}
931933

@@ -1021,6 +1023,7 @@ Examples:
10211023
// Load config and API client
10221024
cfg, err := common.LoadConfig(cmd.Context())
10231025
if err != nil {
1026+
cmd.SilenceUsage = true
10241027
return err
10251028
}
10261029

@@ -1178,6 +1181,7 @@ Examples:
11781181
// Load config and API client
11791182
cfg, err := common.LoadConfig(cmd.Context())
11801183
if err != nil {
1184+
cmd.SilenceUsage = true
11811185
return err
11821186
}
11831187

internal/tiger/cmd/version.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ func buildVersionCmd() *cobra.Command {
3434
Args: cobra.NoArgs,
3535
ValidArgsFunction: cobra.NoFileCompletions,
3636
RunE: func(cmd *cobra.Command, args []string) error {
37+
cmd.SilenceUsage = true
38+
3739
versionOutput := VersionOutput{
3840
Version: config.Version,
3941
BuildTime: config.BuildTime,
@@ -76,7 +78,6 @@ func buildVersionCmd() *cobra.Command {
7678
}
7779
if updateAvailable {
7880
cmd.SilenceErrors = true
79-
cmd.SilenceUsage = true
8081
return common.ExitWithCode(common.ExitUpdateAvailable, nil)
8182
}
8283
return nil

0 commit comments

Comments
 (0)