Skip to content

Commit

Permalink
Switch to errors.New on pre-run checks
Browse files Browse the repository at this point in the history
  • Loading branch information
optik-aper committed Oct 23, 2023
1 parent 72a16c1 commit df7e9a7
Show file tree
Hide file tree
Showing 21 changed files with 24 additions and 23 deletions.
3 changes: 2 additions & 1 deletion cmd/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package cmd

import (
"context"
"errors"
"fmt"
"os"

Expand All @@ -39,7 +40,7 @@ var accountCmd = &cobra.Command{
},
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if auth := cmd.Context().Value("authenticated"); auth != true {
return fmt.Errorf(apiKeyError)
return errors.New(apiKeyError)
}
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Backups() *cobra.Command {
Short: "Display backups",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if auth := cmd.Context().Value("authenticated"); auth != true {
return fmt.Errorf(apiKeyError)
return errors.New(apiKeyError)
}
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/bareMetal.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func BareMetal() *cobra.Command {
Example: bareMetalExample,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if auth := cmd.Context().Value("authenticated"); auth != true {
return fmt.Errorf(apiKeyError)
return errors.New(apiKeyError)
}
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func Billing() *cobra.Command {
Example: billingExample,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if auth := cmd.Context().Value("authenticated"); auth != true {
return fmt.Errorf(apiKeyError)
return errors.New(apiKeyError)
}
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/blockStorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func BlockStorageCmd() *cobra.Command {
Long: `block-storage is used to interact with the block-storage api`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if auth := cmd.Context().Value("authenticated"); auth != true {
return fmt.Errorf(apiKeyError)
return errors.New(apiKeyError)
}
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func Database() *cobra.Command { //nolint:funlen
Example: databaseExample,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if auth := cmd.Context().Value("authenticated"); auth != true {
return fmt.Errorf(apiKeyError)
return errors.New(apiKeyError)
}
return nil
},
Expand Down
4 changes: 2 additions & 2 deletions cmd/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package cmd

import (
"fmt"
"errors"

"github.com/spf13/cobra"
)
Expand All @@ -28,7 +28,7 @@ func DNS() *cobra.Command {
Long: ``,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if auth := cmd.Context().Value("authenticated"); auth != true {
return fmt.Errorf(apiKeyError)
return errors.New(apiKeyError)
}
return nil
},
Expand Down
4 changes: 2 additions & 2 deletions cmd/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package cmd

import (
"fmt"
"errors"

"github.com/spf13/cobra"
)
Expand All @@ -29,7 +29,7 @@ func Firewall() *cobra.Command {
Aliases: []string{"fw"},
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if auth := cmd.Context().Value("authenticated"); auth != true {
return fmt.Errorf(apiKeyError)
return errors.New(apiKeyError)
}
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func Instance() *cobra.Command { //nolint: funlen,gocyclo
Example: instanceExample,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if auth := cmd.Context().Value("authenticated"); auth != true {
return fmt.Errorf(apiKeyError)
return errors.New(apiKeyError)
}
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/iso.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func ISO() *cobra.Command {
Long: ``,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if auth := cmd.Context().Value("authenticated"); auth != true {
return fmt.Errorf(apiKeyError)
return errors.New(apiKeyError)
}
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func Kubernetes() *cobra.Command { //nolint: funlen
Example: kubernetesExample,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if auth := cmd.Context().Value("authenticated"); auth != true {
return fmt.Errorf(apiKeyError)
return errors.New(apiKeyError)
}
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/loadBalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func LoadBalancer() *cobra.Command { //nolint: funlen
Example: lbExample,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if auth := cmd.Context().Value("authenticated"); auth != true {
return fmt.Errorf(apiKeyError)
return errors.New(apiKeyError)
}
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func Network() *cobra.Command {
Deprecated: "Use vpc instead.",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if auth := cmd.Context().Value("authenticated"); auth != true {
return fmt.Errorf(apiKeyError)
return errors.New(apiKeyError)
}
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/objectStorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func ObjectStorageCmd() *cobra.Command {
Long: `object-storage is used to interact with the object-storage api`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if auth := cmd.Context().Value("authenticated"); auth != true {
return fmt.Errorf(apiKeyError)
return errors.New(apiKeyError)
}
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/reservedIP.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func ReservedIP() *cobra.Command {
Example: reservedIPExample,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if auth := cmd.Context().Value("authenticated"); auth != true {
return fmt.Errorf(apiKeyError)
return errors.New(apiKeyError)
}
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func Script() *cobra.Command {
Long: `script is used to access startup script commands`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if auth := cmd.Context().Value("authenticated"); auth != true {
return fmt.Errorf(apiKeyError)
return errors.New(apiKeyError)
}
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func Snapshot() *cobra.Command {
Long: `snapshot is used to access snapshot commands`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if auth := cmd.Context().Value("authenticated"); auth != true {
return fmt.Errorf(apiKeyError)
return errors.New(apiKeyError)
}
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/sshKey.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func SSHKey() *cobra.Command {
Long: `ssh-key is used to access SSH key commands`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if auth := cmd.Context().Value("authenticated"); auth != true {
return fmt.Errorf(apiKeyError)
return errors.New(apiKeyError)
}
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func User() *cobra.Command {
Long: `user is used to access user commands`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if auth := cmd.Context().Value("authenticated"); auth != true {
return fmt.Errorf(apiKeyError)
return errors.New(apiKeyError)
}
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func VPC() *cobra.Command {
Example: vpcExample,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if auth := cmd.Context().Value("authenticated"); auth != true {
return fmt.Errorf(apiKeyError)
return errors.New(apiKeyError)
}
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/vpc2.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func VPC2() *cobra.Command {
Example: vpc2Example,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if auth := cmd.Context().Value("authenticated"); auth != true {
return fmt.Errorf(apiKeyError)
return errors.New(apiKeyError)
}
return nil
},
Expand Down

0 comments on commit df7e9a7

Please sign in to comment.