Skip to content

Commit 5395898

Browse files
authored
refactor: don't ignore errors setting up cobra flags (#358)
Panic instead. These are programming errors, occurring early at startup.
1 parent 096147c commit 5395898

File tree

30 files changed

+59
-52
lines changed

30 files changed

+59
-52
lines changed

internal/commands/account/permissions/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (l *listCommand) InitCommand() {
3737
}
3838

3939
func (l *listCommand) InitCommandWithConfig(cfg *config.Config) {
40-
_ = l.Cobra().RegisterFlagCompletionFunc("username", namedargs.CompletionFunc(completion.Username{}, cfg))
40+
commands.Must(l.Cobra().RegisterFlagCompletionFunc("username", namedargs.CompletionFunc(completion.Username{}, cfg)))
4141
}
4242

4343
func (l *listCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Output, error) {

internal/commands/database/index/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (s *deleteCommand) InitCommand() {
3636
flagSet.StringVar(&s.name, "name", "", "Index name")
3737
s.AddFlags(flagSet)
3838

39-
_ = s.Cobra().MarkFlagRequired("name")
39+
commands.Must(s.Cobra().MarkFlagRequired("name"))
4040
}
4141

4242
// Execute implements commands.MultipleArgumentCommand

internal/commands/database/session/cancel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (s *cancelCommand) InitCommand() {
4141
config.AddToggleFlag(flagSet, &s.terminate, "terminate", false, "Request immediate termination instead of soft cancel.")
4242

4343
s.AddFlags(flagSet)
44-
_ = s.Cobra().MarkFlagRequired("pid")
44+
commands.Must(s.Cobra().MarkFlagRequired("pid"))
4545
}
4646

4747
// Execute implements commands.MultipleArgumentCommand

internal/commands/ipaddress/assign.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (s *assignCommand) InitCommand() {
5757
}
5858

5959
func (s *assignCommand) InitCommandWithConfig(cfg *config.Config) {
60-
_ = s.Cobra().RegisterFlagCompletionFunc("zone", namedargs.CompletionFunc(completion.Zone{}, cfg))
60+
commands.Must(s.Cobra().RegisterFlagCompletionFunc("zone", namedargs.CompletionFunc(completion.Zone{}, cfg)))
6161
}
6262

6363
// ExecuteWithoutArguments implements commands.NoArgumentCommand

internal/commands/kubernetes/create.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,15 @@ func (c *createCommand) InitCommand() {
147147
config.AddToggleFlag(fs, &c.params.wait, "wait", false, "Wait for cluster to be in running state before returning.")
148148
c.AddFlags(fs)
149149

150-
_ = c.Cobra().MarkFlagRequired("name")
151-
_ = c.Cobra().MarkFlagRequired("network")
152-
_ = c.Cobra().MarkFlagRequired("zone")
150+
commands.Must(c.Cobra().MarkFlagRequired("name"))
151+
commands.Must(c.Cobra().MarkFlagRequired("network"))
152+
commands.Must(c.Cobra().MarkFlagRequired("zone"))
153153
}
154154

155155
func (c *createCommand) InitCommandWithConfig(cfg *config.Config) {
156-
_ = c.Cobra().RegisterFlagCompletionFunc("network", namedargs.CompletionFunc(completion.Network{}, cfg))
157-
_ = c.Cobra().RegisterFlagCompletionFunc("zone", namedargs.CompletionFunc(completion.Zone{}, cfg))
158-
_ = c.Cobra().RegisterFlagCompletionFunc("version", namedargs.CompletionFunc(completion.KubernetesVersion{}, cfg))
156+
commands.Must(c.Cobra().RegisterFlagCompletionFunc("network", namedargs.CompletionFunc(completion.Network{}, cfg)))
157+
commands.Must(c.Cobra().RegisterFlagCompletionFunc("zone", namedargs.CompletionFunc(completion.Zone{}, cfg)))
158+
commands.Must(c.Cobra().RegisterFlagCompletionFunc("version", namedargs.CompletionFunc(completion.KubernetesVersion{}, cfg)))
159159
}
160160

161161
// ExecuteWithoutArguments implements commands.NoArgumentCommand

internal/commands/kubernetes/nodegroup/create.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ func (s *createCommand) InitCommand() {
142142
fs := GetCreateNodeGroupFlagSet(&s.p)
143143
s.AddFlags(fs)
144144

145-
_ = s.Cobra().MarkFlagRequired("name")
146-
_ = s.Cobra().MarkFlagRequired("count")
147-
_ = s.Cobra().MarkFlagRequired("plan")
145+
commands.Must(s.Cobra().MarkFlagRequired("name"))
146+
commands.Must(s.Cobra().MarkFlagRequired("count"))
147+
commands.Must(s.Cobra().MarkFlagRequired("plan"))
148148
}
149149

150150
// ExecuteSingleArgument implements commands.SingleArgumentCommand

internal/commands/kubernetes/nodegroup/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (s *deleteCommand) InitCommand() {
3535
flagSet.StringVar(&s.name, "name", "", "Node group name")
3636
s.AddFlags(flagSet)
3737

38-
_ = s.Cobra().MarkFlagRequired("name")
38+
commands.Must(s.Cobra().MarkFlagRequired("name"))
3939
}
4040

4141
// ExecuteSingleArgument implements commands.SingleArgumentCommand

internal/commands/kubernetes/nodegroup/scale.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ func (s *scaleCommand) InitCommand() {
3737
flagSet.IntVar(&s.count, "count", 0, "Node count")
3838
s.AddFlags(flagSet)
3939

40-
_ = s.Cobra().MarkFlagRequired("name")
41-
_ = s.Cobra().MarkFlagRequired("count")
40+
commands.Must(s.Cobra().MarkFlagRequired("name"))
41+
commands.Must(s.Cobra().MarkFlagRequired("count"))
4242
}
4343

4444
// ExecuteSingleArgument implements commands.SingleArgumentCommand

internal/commands/kubernetes/nodegroup/show.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (s *showCommand) InitCommand() {
3737
flagSet.StringVar(&s.name, "name", "", "Node group name")
3838
s.AddFlags(flagSet)
3939

40-
_ = s.Cobra().MarkFlagRequired("name")
40+
commands.Must(s.Cobra().MarkFlagRequired("name"))
4141
}
4242

4343
// ExecuteSingleArgument implements commands.SingleArgumentCommand

internal/commands/network/create.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ func (s *createCommand) InitCommand() {
5555
" dhcp-dns: array of strings")
5656

5757
s.AddFlags(fs)
58-
_ = s.Cobra().MarkFlagRequired("name")
59-
_ = s.Cobra().MarkFlagRequired("zone")
60-
_ = s.Cobra().MarkFlagRequired("ip-network")
58+
commands.Must(s.Cobra().MarkFlagRequired("name"))
59+
commands.Must(s.Cobra().MarkFlagRequired("zone"))
60+
commands.Must(s.Cobra().MarkFlagRequired("ip-network"))
6161
}
6262

6363
func (s *createCommand) InitCommandWithConfig(cfg *config.Config) {
64-
_ = s.Cobra().RegisterFlagCompletionFunc("zone", namedargs.CompletionFunc(completion.Zone{}, cfg))
64+
commands.Must(s.Cobra().RegisterFlagCompletionFunc("zone", namedargs.CompletionFunc(completion.Zone{}, cfg)))
6565
}
6666

6767
// MaximumExecutions implements Command.MaximumExecutions

0 commit comments

Comments
 (0)