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..d7d1a912 100644 --- a/cmd/collect/inventory.go +++ b/cmd/collect/inventory.go @@ -17,7 +17,6 @@ import ( ) type collectInventoryFlags struct { - serverID string skipFirmwareStatusCollect bool skipBiosConfigCollect bool } @@ -27,9 +26,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 +37,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 +80,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) } diff --git a/docs/mctl_collect.md b/docs/mctl_collect.md index 1ff4d062..4e6e3f16 100644 --- a/docs/mctl_collect.md +++ b/docs/mctl_collect.md @@ -11,7 +11,8 @@ mctl collect [flags] ### Options ``` - -h, --help help for collect + -h, --help help for collect + -s, --server string server id (typically a UUID) ``` ### Options inherited from parent commands diff --git a/docs/mctl_collect_inventory.md b/docs/mctl_collect_inventory.md index 3408073d..fb200959 100644 --- a/docs/mctl_collect_inventory.md +++ b/docs/mctl_collect_inventory.md @@ -5,14 +5,13 @@ Collect current server firmware status and bios configuration ``` -mctl collect inventory [flags] +mctl collect inventory --server | -s [flags] ``` ### Options ``` -h, --help help for inventory - --server string server UUID --skip-bios-config Skip BIOS configuration data collection --skip-fw-status Skip firmware status data collection ``` @@ -22,6 +21,7 @@ mctl collect inventory [flags] ``` --config string config file (default is $XDG_CONFIG_HOME/mctl/config.yml) --reauth re-authenticate with oauth services + -s, --server string server id (typically a UUID) ``` ### SEE ALSO diff --git a/docs/mctl_collect_status.md b/docs/mctl_collect_status.md index 0a16f147..cb28d03c 100644 --- a/docs/mctl_collect_status.md +++ b/docs/mctl_collect_status.md @@ -11,8 +11,7 @@ mctl collect status --server | -s [flags] ### Options ``` - -h, --help help for status - -s, --server string server id (typically a UUID) + -h, --help help for status ``` ### Options inherited from parent commands @@ -20,6 +19,7 @@ mctl collect status --server | -s [flags] ``` --config string config file (default is $XDG_CONFIG_HOME/mctl/config.yml) --reauth re-authenticate with oauth services + -s, --server string server id (typically a UUID) ``` ### SEE ALSO