diff --git a/cmd/collect/collect.go b/cmd/collect/collect.go index 43ecc1e7..8a3b37d9 100644 --- a/cmd/collect/collect.go +++ b/cmd/collect/collect.go @@ -1,10 +1,14 @@ package collect import ( + "log" + "github.com/metal-toolbox/mctl/cmd" "github.com/spf13/cobra" ) +var serverIDStr string + var collect = &cobra.Command{ Use: "collect", Short: "Collect current server firmware status and bios configuration", @@ -16,4 +20,11 @@ var collect = &cobra.Command{ func init() { cmd.RootCmd.AddCommand(collect) + + pflags := collect.PersistentFlags() + pflags.StringVarP(&serverIDStr, "server", "s", "", "server id (typically a UUID)") + + if err := collect.MarkPersistentFlagRequired("server"); err != nil { + log.Fatalf("marking server flag as required: %s", err.Error()) + } } diff --git a/cmd/collect/inventory.go b/cmd/collect/inventory.go index b04bc402..cc140916 100644 --- a/cmd/collect/inventory.go +++ b/cmd/collect/inventory.go @@ -27,9 +27,9 @@ var ( ) var collectInventoryCmd = &cobra.Command{ - Use: "inventory", + Use: "inventory --server | -s ", Short: "Collect current server firmware status and bios configuration", - Run: func(cmd *cobra.Command, args []string) { + Run: func(cmd *cobra.Command, _ []string) { collectInventory(cmd.Context()) }, @@ -38,7 +38,7 @@ var collectInventoryCmd = &cobra.Command{ func collectInventory(ctx context.Context) { theApp := mctl.MustCreateApp(ctx) - serverID, err := uuid.Parse(flagsDefinedCollectInventory.serverID) + serverID, err := uuid.Parse(serverIDStr) if err != nil { log.Fatal(err) } @@ -81,11 +81,8 @@ func init() { flagsDefinedCollectInventory = &collectInventoryFlags{} collect.AddCommand(collectInventoryCmd) - collectInventoryCmd.PersistentFlags().StringVar(&flagsDefinedCollectInventory.serverID, "server", "", "server UUID") - collectInventoryCmd.PersistentFlags().BoolVar(&flagsDefinedCollectInventory.skipFirmwareStatusCollect, "skip-fw-status", false, "Skip firmware status data collection") - collectInventoryCmd.PersistentFlags().BoolVar(&flagsDefinedCollectInventory.skipBiosConfigCollect, "skip-bios-config", false, "Skip BIOS configuration data collection") - - if err := collectInventoryCmd.MarkPersistentFlagRequired("server"); err != nil { - log.Fatal(err) - } + collectInventoryCmd.PersistentFlags().BoolVar(&flagsDefinedCollectInventory.skipFirmwareStatusCollect, + "skip-fw-status", false, "Skip firmware status data collection") + collectInventoryCmd.PersistentFlags().BoolVar(&flagsDefinedCollectInventory.skipBiosConfigCollect, + "skip-bios-config", false, "Skip BIOS configuration data collection") } diff --git a/cmd/collect/status.go b/cmd/collect/status.go index 10c2289f..6a98bddf 100644 --- a/cmd/collect/status.go +++ b/cmd/collect/status.go @@ -15,8 +15,6 @@ import ( rctypes "github.com/metal-toolbox/rivets/condition" ) -var serverIDStr string - var inventoryStatus = &cobra.Command{ Use: "status --server | -s ", Short: "check the progress of a inventory collection for a server", @@ -53,12 +51,5 @@ func statusCheck(ctx context.Context) { } func init() { - flags := inventoryStatus.Flags() - flags.StringVarP(&serverIDStr, "server", "s", "", "server id (typically a UUID)") - - if err := inventoryStatus.MarkFlagRequired("server"); err != nil { - log.Fatalf("marking server flag as required: %s", err.Error()) - } - collect.AddCommand(inventoryStatus) }