From 179d35fedf96757f8e80765ff2857d39dc4091e3 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Wed, 19 Jun 2024 15:17:14 -0400 Subject: [PATCH 1/3] cli: Rename partitionFormatPartitionCommand -> partitionFormatCommand Typo when doing the first rename. --- cmd/partition_format.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/partition_format.go b/cmd/partition_format.go index 45e86a5..8e3df71 100644 --- a/cmd/partition_format.go +++ b/cmd/partition_format.go @@ -7,7 +7,7 @@ import ( "github.com/spf13/cobra" ) -var partitionFormatPartitionCommand = &cobra.Command{ +var partitionFormatCommand = &cobra.Command{ Use: "format", Short: "Formats a partition", Long: "Formats a partition with your choice of filesystem", @@ -49,21 +49,21 @@ var partitionFormatPartitionCommand = &cobra.Command{ } func init() { - partitionFormatPartitionCommand.PersistentFlags().String("device", "", "Block device") - partitionFormatPartitionCommand.PersistentFlags().String("filesystem-device", "", "Filesystem Block device") + partitionFormatCommand.PersistentFlags().String("device", "", "Block device") + partitionFormatCommand.PersistentFlags().String("filesystem-device", "", "Filesystem Block device") - partitionFormatPartitionCommand.PersistentFlags().Uint("partition", 0, "Partition number") + partitionFormatCommand.PersistentFlags().Uint("partition", 0, "Partition number") - partitionFormatPartitionCommand.PersistentFlags().String("format", "ext4", "Filesystem to be applied to the partition") - markFlagAsRequired(partitionFormatPartitionCommand, "format") + partitionFormatCommand.PersistentFlags().String("format", "ext4", "Filesystem to be applied to the partition") + markFlagAsRequired(partitionFormatCommand, "format") - partitionFormatPartitionCommand.PersistentFlags().String("mount-point", "/", "Filesystem mount point") - partitionFormatPartitionCommand.PersistentFlags().StringSlice("options", []string{}, "Filesystem creation options") - partitionCommand.AddCommand(partitionFormatPartitionCommand) + partitionFormatCommand.PersistentFlags().String("mount-point", "/", "Filesystem mount point") + partitionFormatCommand.PersistentFlags().StringSlice("options", []string{}, "Filesystem creation options") + partitionCommand.AddCommand(partitionFormatCommand) rootCmd.AddCommand(&cobra.Command{ Use: "format-partition", Deprecated: "use \"partition format\"", - Run: partitionFormatPartitionCommand.Run, + Run: partitionFormatCommand.Run, }) } From 9c4c7073a158580096d349b181751ccd7024a4da Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Wed, 19 Jun 2024 15:17:40 -0400 Subject: [PATCH 2/3] cli: Implement deprecation using shallow copy Shallow copy also gets us the flags, without the shallow copy the Run will error accessing non-existent flags. --- cmd/disk_partition.go | 9 ++++----- cmd/partition_format.go | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/cmd/disk_partition.go b/cmd/disk_partition.go index a775029..b5d24c1 100644 --- a/cmd/disk_partition.go +++ b/cmd/disk_partition.go @@ -43,9 +43,8 @@ func init() { diskCommand.AddCommand(diskPartitionCommand) - rootCmd.AddCommand(&cobra.Command{ - Use: "partition-disk", - Deprecated: "use \"disk partition\"", - Run: diskPartitionCommand.Run, - }) + deprecated := *diskPartitionCommand + deprecated.Use = "partition-disk" + deprecated.Deprecated = "use \"disk partition\"" + rootCmd.AddCommand(&deprecated) } diff --git a/cmd/partition_format.go b/cmd/partition_format.go index 8e3df71..cadaccc 100644 --- a/cmd/partition_format.go +++ b/cmd/partition_format.go @@ -61,9 +61,8 @@ func init() { partitionFormatCommand.PersistentFlags().StringSlice("options", []string{}, "Filesystem creation options") partitionCommand.AddCommand(partitionFormatCommand) - rootCmd.AddCommand(&cobra.Command{ - Use: "format-partition", - Deprecated: "use \"partition format\"", - Run: partitionFormatCommand.Run, - }) + deprecated := *partitionFormatCommand + deprecated.Use = "format-partition" + deprecated.Deprecated = "use \"partition format\"" + rootCmd.AddCommand(&deprecated) } From f2745d07a3bdb2a983286177947c9fb98f372dca Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Wed, 19 Jun 2024 15:23:11 -0400 Subject: [PATCH 3/3] cli: Fix flag usage Was missing --timeout and should have use --debug like the rest of the commands instead of --verbose. --- cmd/disk_wipe.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/disk_wipe.go b/cmd/disk_wipe.go index dc89cba..7a48cec 100644 --- a/cmd/disk_wipe.go +++ b/cmd/disk_wipe.go @@ -5,6 +5,7 @@ import ( "context" "errors" "os" + "time" "github.com/bmc-toolbox/common" "github.com/metal-toolbox/ironlib" @@ -32,9 +33,9 @@ func init() { logger.With("error", err).Fatal("--timeout argument is invalid") } - verbose, err := cmd.Flags().GetBool("verbose") + verbose, err := cmd.Flags().GetBool("debug") if err != nil { - logger.With("error", err).Fatal("--verbose argument is invalid") + logger.With("error", err).Fatal("--debug argument is invalid") } driveName := args[0] @@ -90,5 +91,6 @@ func init() { }, } + diskCommand.PersistentFlags().Duration("timeout", 1*time.Minute, "Time to wait for wipe to complete") diskCommand.AddCommand(cmd) }