Skip to content

Commit

Permalink
Use Must from genericcli. (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 authored May 7, 2024
1 parent 07cd824 commit 0265699
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 128 deletions.
6 changes: 3 additions & 3 deletions cmd/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ func newAuditCmd(c *config) *cobra.Command {

cmd.Flags().Int64("limit", 100, "limit the number of audit traces.")

must(cmd.RegisterFlagCompletionFunc("type", c.comp.AuditTypeCompletion))
must(cmd.RegisterFlagCompletionFunc("phase", c.comp.AuditPhaseCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("type", c.comp.AuditTypeCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("phase", c.comp.AuditPhaseCompletion))
},
DescribeCmdMutateFn: func(cmd *cobra.Command) {
cmd.Flags().Bool("prettify-body", false, "attempts to interpret the body as json and prettifies it")
cmd.Flags().String("phase", "response", "phase of the audit trace. One of [request, response, single, error, opened, closed]")

must(cmd.RegisterFlagCompletionFunc("phase", c.comp.AuditPhaseCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("phase", c.comp.AuditPhaseCompletion))
},
OnlyCmds: genericcli.OnlyCmds(
genericcli.ListCmd,
Expand Down
16 changes: 8 additions & 8 deletions cmd/filesystemlayout.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ func newFilesystemLayoutCmd(c *config) *cobra.Command {

tryCmd.Flags().StringP("size", "", "", "size to try")
tryCmd.Flags().StringP("image", "", "", "image to try")
must(tryCmd.MarkFlagRequired("size"))
must(tryCmd.MarkFlagRequired("image"))
must(tryCmd.RegisterFlagCompletionFunc("size", c.comp.SizeListCompletion))
must(tryCmd.RegisterFlagCompletionFunc("image", c.comp.ImageListCompletion))
genericcli.Must(tryCmd.MarkFlagRequired("size"))
genericcli.Must(tryCmd.MarkFlagRequired("image"))
genericcli.Must(tryCmd.RegisterFlagCompletionFunc("size", c.comp.SizeListCompletion))
genericcli.Must(tryCmd.RegisterFlagCompletionFunc("image", c.comp.ImageListCompletion))

matchCmd := &cobra.Command{
Use: "match",
Expand All @@ -62,10 +62,10 @@ func newFilesystemLayoutCmd(c *config) *cobra.Command {

matchCmd.Flags().StringP("machine", "", "", "machine id to check for match [required]")
matchCmd.Flags().StringP("filesystemlayout", "", "", "filesystemlayout id to check against [required]")
must(matchCmd.MarkFlagRequired("machine"))
must(matchCmd.MarkFlagRequired("filesystemlayout"))
must(matchCmd.RegisterFlagCompletionFunc("machine", c.comp.MachineListCompletion))
must(matchCmd.RegisterFlagCompletionFunc("filesystemlayout", c.comp.FilesystemLayoutListCompletion))
genericcli.Must(matchCmd.MarkFlagRequired("machine"))
genericcli.Must(matchCmd.MarkFlagRequired("filesystemlayout"))
genericcli.Must(matchCmd.RegisterFlagCompletionFunc("machine", c.comp.MachineListCompletion))
genericcli.Must(matchCmd.RegisterFlagCompletionFunc("filesystemlayout", c.comp.FilesystemLayoutListCompletion))

return genericcli.NewCmds(cmdsConfig, tryCmd, matchCmd)
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func newFirewallCmd(c *config) *cobra.Command {
c.addMachineCreateFlags(cmd, "firewall")
cmd.Aliases = []string{"allocate"}
cmd.Flags().String("firewall-rules-file", "", `firewall rules specified in a yaml file
Example:
$ metalctl firewall create ..mandatory args.. --firewall-rules-file rules.yaml
Expand Down Expand Up @@ -104,11 +104,11 @@ ingress:
cmd.Flags().String("hostname", "", "allocation hostname to filter [optional]")
cmd.Flags().String("mac", "", "mac to filter [optional]")
cmd.Flags().StringSlice("tags", []string{}, "tags to filter, use it like: --tags \"tag1,tag2\" or --tags \"tag3\".")
must(cmd.RegisterFlagCompletionFunc("partition", c.comp.PartitionListCompletion))
must(cmd.RegisterFlagCompletionFunc("size", c.comp.SizeListCompletion))
must(cmd.RegisterFlagCompletionFunc("project", c.comp.ProjectListCompletion))
must(cmd.RegisterFlagCompletionFunc("id", c.comp.FirewallListCompletion))
must(cmd.RegisterFlagCompletionFunc("image", c.comp.ImageListCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("partition", c.comp.PartitionListCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("size", c.comp.SizeListCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.comp.ProjectListCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("id", c.comp.FirewallListCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("image", c.comp.ImageListCompletion))
},
}

Expand Down
44 changes: 22 additions & 22 deletions cmd/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,30 @@ func newFirmwareCmd(c *config) *cobra.Command {
firmwareListCmd.Flags().StringP("vendor", "", "", "the vendor")
firmwareListCmd.Flags().StringP("board", "", "", "the board type")
firmwareListCmd.Flags().StringP("machineid", "", "", "the machine id (ignores vendor and board flags)")
must(firmwareListCmd.RegisterFlagCompletionFunc("kind", c.comp.FirmwareKindCompletion))
must(firmwareListCmd.RegisterFlagCompletionFunc("vendor", c.comp.FirmwareVendorCompletion))
must(firmwareListCmd.RegisterFlagCompletionFunc("board", c.comp.FirmwareBoardCompletion))
must(firmwareListCmd.RegisterFlagCompletionFunc("machineid", c.comp.MachineListCompletion))
genericcli.Must(firmwareListCmd.RegisterFlagCompletionFunc("kind", c.comp.FirmwareKindCompletion))
genericcli.Must(firmwareListCmd.RegisterFlagCompletionFunc("vendor", c.comp.FirmwareVendorCompletion))
genericcli.Must(firmwareListCmd.RegisterFlagCompletionFunc("board", c.comp.FirmwareBoardCompletion))
genericcli.Must(firmwareListCmd.RegisterFlagCompletionFunc("machineid", c.comp.MachineListCompletion))
firmwareCmd.AddCommand(firmwareListCmd)

firmwareUploadBiosCmd.Flags().StringP("vendor", "", "", "the vendor (required)")
firmwareUploadBiosCmd.Flags().StringP("board", "", "", "the board type (required)")
firmwareUploadBiosCmd.Flags().StringP("revision", "", "", "the BIOS firmware revision (required)")
must(firmwareUploadBiosCmd.MarkFlagRequired("vendor"))
must(firmwareUploadBiosCmd.MarkFlagRequired("board"))
must(firmwareUploadBiosCmd.MarkFlagRequired("revision"))
must(firmwareUploadBiosCmd.RegisterFlagCompletionFunc("vendor", c.comp.FirmwareVendorCompletion))
must(firmwareUploadBiosCmd.RegisterFlagCompletionFunc("board", c.comp.FirmwareBoardCompletion))
genericcli.Must(firmwareUploadBiosCmd.MarkFlagRequired("vendor"))
genericcli.Must(firmwareUploadBiosCmd.MarkFlagRequired("board"))
genericcli.Must(firmwareUploadBiosCmd.MarkFlagRequired("revision"))
genericcli.Must(firmwareUploadBiosCmd.RegisterFlagCompletionFunc("vendor", c.comp.FirmwareVendorCompletion))
genericcli.Must(firmwareUploadBiosCmd.RegisterFlagCompletionFunc("board", c.comp.FirmwareBoardCompletion))
firmwareUploadCmd.AddCommand(firmwareUploadBiosCmd)

firmwareUploadBmcCmd.Flags().StringP("vendor", "", "", "the vendor (required)")
firmwareUploadBmcCmd.Flags().StringP("board", "", "", "the board type (required)")
firmwareUploadBmcCmd.Flags().StringP("revision", "", "", "the BMC firmware revision (required)")
must(firmwareUploadBmcCmd.MarkFlagRequired("vendor"))
must(firmwareUploadBmcCmd.MarkFlagRequired("board"))
must(firmwareUploadBmcCmd.MarkFlagRequired("revision"))
must(firmwareUploadBmcCmd.RegisterFlagCompletionFunc("vendor", c.comp.FirmwareVendorCompletion))
must(firmwareUploadBmcCmd.RegisterFlagCompletionFunc("board", c.comp.FirmwareBoardCompletion))
genericcli.Must(firmwareUploadBmcCmd.MarkFlagRequired("vendor"))
genericcli.Must(firmwareUploadBmcCmd.MarkFlagRequired("board"))
genericcli.Must(firmwareUploadBmcCmd.MarkFlagRequired("revision"))
genericcli.Must(firmwareUploadBmcCmd.RegisterFlagCompletionFunc("vendor", c.comp.FirmwareVendorCompletion))
genericcli.Must(firmwareUploadBmcCmd.RegisterFlagCompletionFunc("board", c.comp.FirmwareBoardCompletion))
firmwareUploadCmd.AddCommand(firmwareUploadBmcCmd)

firmwareCmd.AddCommand(firmwareUploadCmd)
Expand All @@ -99,14 +99,14 @@ func newFirmwareCmd(c *config) *cobra.Command {
firmwareRemoveCmd.Flags().StringP("vendor", "", "", "the vendor (required)")
firmwareRemoveCmd.Flags().StringP("board", "", "", "the board type (required)")
firmwareRemoveCmd.Flags().StringP("revision", "", "", "the firmware revision (required)")
must(firmwareRemoveCmd.MarkFlagRequired("kind"))
must(firmwareRemoveCmd.MarkFlagRequired("vendor"))
must(firmwareRemoveCmd.MarkFlagRequired("board"))
must(firmwareRemoveCmd.MarkFlagRequired("revision"))
must(firmwareRemoveCmd.RegisterFlagCompletionFunc("kind", c.comp.FirmwareKindCompletion))
must(firmwareRemoveCmd.RegisterFlagCompletionFunc("vendor", c.comp.FirmwareVendorCompletion))
must(firmwareRemoveCmd.RegisterFlagCompletionFunc("board", c.comp.FirmwareBoardCompletion))
must(firmwareRemoveCmd.RegisterFlagCompletionFunc("revision", c.comp.FirmwareRevisionCompletion))
genericcli.Must(firmwareRemoveCmd.MarkFlagRequired("kind"))
genericcli.Must(firmwareRemoveCmd.MarkFlagRequired("vendor"))
genericcli.Must(firmwareRemoveCmd.MarkFlagRequired("board"))
genericcli.Must(firmwareRemoveCmd.MarkFlagRequired("revision"))
genericcli.Must(firmwareRemoveCmd.RegisterFlagCompletionFunc("kind", c.comp.FirmwareKindCompletion))
genericcli.Must(firmwareRemoveCmd.RegisterFlagCompletionFunc("vendor", c.comp.FirmwareVendorCompletion))
genericcli.Must(firmwareRemoveCmd.RegisterFlagCompletionFunc("board", c.comp.FirmwareBoardCompletion))
genericcli.Must(firmwareRemoveCmd.RegisterFlagCompletionFunc("revision", c.comp.FirmwareRevisionCompletion))
firmwareCmd.AddCommand(firmwareRemoveCmd)

return firmwareCmd
Expand Down
12 changes: 6 additions & 6 deletions cmd/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ func newImageCmd(c *config) *cobra.Command {
cmd.Flags().String("os", "", "OS derivate of this image.")
cmd.Flags().String("version", "", "Version of this image.")

must(cmd.RegisterFlagCompletionFunc("id", c.comp.ImageListCompletion))
must(cmd.RegisterFlagCompletionFunc("name", c.comp.ImageNameCompletion))
must(cmd.RegisterFlagCompletionFunc("classification", c.comp.ImageClassificationCompletion))
must(cmd.RegisterFlagCompletionFunc("features", c.comp.ImageFeatureCompletion))
must(cmd.RegisterFlagCompletionFunc("os", c.comp.ImageOSCompletion))
must(cmd.RegisterFlagCompletionFunc("version", c.comp.ImageVersionCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("id", c.comp.ImageListCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("name", c.comp.ImageNameCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("classification", c.comp.ImageClassificationCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("features", c.comp.ImageFeatureCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("os", c.comp.ImageOSCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("version", c.comp.ImageVersionCompletion))
},
}

Expand Down
16 changes: 8 additions & 8 deletions cmd/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ func newIPCmd(c *config) *cobra.Command {
cmd.Flags().StringP("network", "", "", "network from where the IP should be allocated.")
cmd.Flags().StringP("project", "", "", "project for which the IP should be allocated.")
cmd.Flags().StringSliceP("tags", "", nil, "tags to attach to the IP.")
must(cmd.RegisterFlagCompletionFunc("network", c.comp.NetworkListCompletion))
must(cmd.RegisterFlagCompletionFunc("project", c.comp.ProjectListCompletion))
must(cmd.RegisterFlagCompletionFunc("type", cobra.FixedCompletions([]string{models.V1IPAllocateRequestTypeEphemeral, models.V1IPAllocateRequestTypeStatic}, cobra.ShellCompDirectiveNoFileComp)))
genericcli.Must(cmd.RegisterFlagCompletionFunc("network", c.comp.NetworkListCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.comp.ProjectListCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("type", cobra.FixedCompletions([]string{models.V1IPAllocateRequestTypeEphemeral, models.V1IPAllocateRequestTypeStatic}, cobra.ShellCompDirectiveNoFileComp)))
},
ListCmdMutateFn: func(cmd *cobra.Command) {
cmd.Flags().StringP("ipaddress", "", "", "ipaddress to filter [optional]")
Expand All @@ -62,11 +62,11 @@ func newIPCmd(c *config) *cobra.Command {
cmd.Flags().StringP("network", "", "", "network to filter [optional]")
cmd.Flags().StringP("name", "", "", "name to filter [optional]")
cmd.Flags().StringSliceP("tags", "", nil, "tags to filter [optional]")
must(cmd.RegisterFlagCompletionFunc("ipaddress", c.comp.IpListCompletion))
must(cmd.RegisterFlagCompletionFunc("network", c.comp.NetworkListCompletion))
must(cmd.RegisterFlagCompletionFunc("project", c.comp.ProjectListCompletion))
must(cmd.RegisterFlagCompletionFunc("type", cobra.FixedCompletions([]string{models.V1IPAllocateRequestTypeEphemeral, models.V1IPAllocateRequestTypeStatic}, cobra.ShellCompDirectiveNoFileComp)))
must(cmd.RegisterFlagCompletionFunc("machineid", c.comp.MachineListCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("ipaddress", c.comp.IpListCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("network", c.comp.NetworkListCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.comp.ProjectListCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("type", cobra.FixedCompletions([]string{models.V1IPAllocateRequestTypeEphemeral, models.V1IPAllocateRequestTypeStatic}, cobra.ShellCompDirectiveNoFileComp)))
genericcli.Must(cmd.RegisterFlagCompletionFunc("machineid", c.comp.MachineListCompletion))
},
DeleteCmdMutateFn: func(cmd *cobra.Command) {
cmd.Aliases = append(cmd.Aliases, "free")
Expand Down
30 changes: 15 additions & 15 deletions cmd/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (c *machineCmd) listCmdFlags(cmd *cobra.Command, lastEventErrorThresholdDef

for _, c := range listFlagCompletions {
c := c
must(cmd.RegisterFlagCompletionFunc(c.flagName, c.f))
genericcli.Must(cmd.RegisterFlagCompletionFunc(c.flagName, c.f))
}

cmd.Long = cmd.Short + "\n" + api.EmojiHelpText()
Expand Down Expand Up @@ -405,22 +405,22 @@ In case the machine did not register properly a direct ipmi console access is av
machineIssuesCmd.Flags().StringSlice("omit", nil, "issue types to omit [optional]")
machineIssuesCmd.Flags().String("severity", "", "issue severity to include [optional]")

must(machineIssuesCmd.RegisterFlagCompletionFunc("severity", c.comp.IssueSeverityCompletion))
must(machineIssuesCmd.RegisterFlagCompletionFunc("omit", c.comp.IssueTypeCompletion))
must(machineIssuesCmd.RegisterFlagCompletionFunc("only", c.comp.IssueTypeCompletion))
genericcli.Must(machineIssuesCmd.RegisterFlagCompletionFunc("severity", c.comp.IssueSeverityCompletion))
genericcli.Must(machineIssuesCmd.RegisterFlagCompletionFunc("omit", c.comp.IssueTypeCompletion))
genericcli.Must(machineIssuesCmd.RegisterFlagCompletionFunc("only", c.comp.IssueTypeCompletion))

machineLogsCmd.Flags().Duration("last-event-error-threshold", 7*24*time.Hour, "the duration up to how long in the past a machine last event error will be counted as an issue [optional]")

machineConsolePasswordCmd.Flags().StringP("reason", "", "", "a short description why access to the consolepassword is required")

machineUpdateBiosCmd.Flags().StringP("revision", "", "", "the BIOS revision")
machineUpdateBiosCmd.Flags().StringP("description", "", "", "the reason why the BIOS should be updated")
must(machineUpdateBiosCmd.RegisterFlagCompletionFunc("revision", c.comp.FirmwareBiosRevisionCompletion))
genericcli.Must(machineUpdateBiosCmd.RegisterFlagCompletionFunc("revision", c.comp.FirmwareBiosRevisionCompletion))
machineUpdateFirmwareCmd.AddCommand(machineUpdateBiosCmd)

machineUpdateBmcCmd.Flags().StringP("revision", "", "", "the BMC revision")
machineUpdateBmcCmd.Flags().StringP("description", "", "", "the reason why the BMC should be updated")
must(machineUpdateBmcCmd.RegisterFlagCompletionFunc("revision", c.comp.FirmwareBmcRevisionCompletion))
genericcli.Must(machineUpdateBmcCmd.RegisterFlagCompletionFunc("revision", c.comp.FirmwareBmcRevisionCompletion))
machineUpdateFirmwareCmd.AddCommand(machineUpdateBmcCmd)

machinePowerCmd.AddCommand(machinePowerOnCmd)
Expand All @@ -445,7 +445,7 @@ In case the machine did not register properly a direct ipmi console access is av

machineReinstallCmd.Flags().StringP("image", "", "", "id of the image to get installed. [required]")
machineReinstallCmd.Flags().StringP("description", "d", "", "description of the reinstallation. [optional]")
must(machineReinstallCmd.MarkFlagRequired("image"))
genericcli.Must(machineReinstallCmd.MarkFlagRequired("image"))

machineConsoleCmd.Flags().StringP("sshidentity", "p", "", "SSH key file, if not given the default ssh key will be used if present [optional].")
machineConsoleCmd.Flags().BoolP("ipmi", "", false, "use ipmitool with direct network access (admin only).")
Expand Down Expand Up @@ -524,14 +524,14 @@ MODE can be omitted or one of:
cmd.MarkFlagsRequiredTogether("size", "partition")

// Completion for arguments
must(cmd.RegisterFlagCompletionFunc("networks", c.comp.NetworkListCompletion))
must(cmd.RegisterFlagCompletionFunc("ips", c.comp.IpListCompletion))
must(cmd.RegisterFlagCompletionFunc("partition", c.comp.PartitionListCompletion))
must(cmd.RegisterFlagCompletionFunc("size", c.comp.SizeListCompletion))
must(cmd.RegisterFlagCompletionFunc("project", c.comp.ProjectListCompletion))
must(cmd.RegisterFlagCompletionFunc("id", c.comp.MachineListCompletion))
must(cmd.RegisterFlagCompletionFunc("image", c.comp.ImageListCompletion))
must(cmd.RegisterFlagCompletionFunc("filesystemlayout", c.comp.FilesystemLayoutListCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("networks", c.comp.NetworkListCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("ips", c.comp.IpListCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("partition", c.comp.PartitionListCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("size", c.comp.SizeListCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.comp.ProjectListCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("id", c.comp.MachineListCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("image", c.comp.ImageListCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("filesystemlayout", c.comp.FilesystemLayoutListCompletion))
}

func (c machineCmd) Get(id string) (*models.V1MachineResponse, error) {
Expand Down
9 changes: 0 additions & 9 deletions cmd/must.go

This file was deleted.

Loading

0 comments on commit 0265699

Please sign in to comment.