From 3e106dbac8d735fd031afdce8d3f9d6636a9752b Mon Sep 17 00:00:00 2001 From: Georgi Matev Date: Fri, 27 Jan 2023 12:47:15 -0800 Subject: [PATCH] Warning in the help messages for pre-release hidden commands (#2307) ## Description A basic mechanism to show a warning for the help output of pre-release commands ## Does this PR need a docs update or release note? - [ ] :white_check_mark: Yes, it's included - [ ] :clock1: Yes, but in a later PR - [x] :no_entry: No ## Type of change - [x] :sunflower: Feature - [ ] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Test - [ ] :computer: CI/Deployment - [ ] :broom: Tech Debt/Cleanup ## Issue(s) ## Test Plan - [x] :muscle: Manual - [ ] :zap: Unit test - [ ] :green_heart: E2E --- src/cli/backup/sharepoint.go | 8 ++++---- src/cli/restore/sharepoint.go | 2 +- src/cli/utils/utils.go | 18 +++++++++++++++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/cli/backup/sharepoint.go b/src/cli/backup/sharepoint.go index 26d819b27..45d885b80 100644 --- a/src/cli/backup/sharepoint.go +++ b/src/cli/backup/sharepoint.go @@ -81,7 +81,7 @@ func addSharePointCommands(cmd *cobra.Command) *cobra.Command { switch cmd.Use { case createCommand: - c, fs = utils.AddCommand(cmd, sharePointCreateCmd(), utils.HideCommand()) + c, fs = utils.AddCommand(cmd, sharePointCreateCmd(), utils.MarkPreReleaseCommand()) c.Use = c.Use + " " + sharePointServiceCommandCreateUseSuffix c.Example = sharePointServiceCommandCreateExamples @@ -101,14 +101,14 @@ func addSharePointCommands(cmd *cobra.Command) *cobra.Command { options.AddOperationFlags(c) case listCommand: - c, fs = utils.AddCommand(cmd, sharePointListCmd(), utils.HideCommand()) + c, fs = utils.AddCommand(cmd, sharePointListCmd(), utils.MarkPreReleaseCommand()) fs.StringVar(&backupID, utils.BackupFN, "", "ID of the backup to retrieve.") case detailsCommand: - c, fs = utils.AddCommand(cmd, sharePointDetailsCmd(), utils.HideCommand()) + c, fs = utils.AddCommand(cmd, sharePointDetailsCmd(), utils.MarkPreReleaseCommand()) c.Use = c.Use + " " + sharePointServiceCommandDetailsUseSuffix c.Example = sharePointServiceCommandDetailsExamples @@ -157,7 +157,7 @@ func addSharePointCommands(cmd *cobra.Command) *cobra.Command { // "Select backup details for items created after this datetime.") case deleteCommand: - c, fs = utils.AddCommand(cmd, sharePointDeleteCmd(), utils.HideCommand()) + c, fs = utils.AddCommand(cmd, sharePointDeleteCmd(), utils.MarkPreReleaseCommand()) c.Use = c.Use + " " + sharePointServiceCommandDeleteUseSuffix c.Example = sharePointServiceCommandDeleteExamples diff --git a/src/cli/restore/sharepoint.go b/src/cli/restore/sharepoint.go index 1c3a81e89..13414f6b6 100644 --- a/src/cli/restore/sharepoint.go +++ b/src/cli/restore/sharepoint.go @@ -33,7 +33,7 @@ func addSharePointCommands(cmd *cobra.Command) *cobra.Command { switch cmd.Use { case restoreCommand: - c, fs = utils.AddCommand(cmd, sharePointRestoreCmd(), utils.HideCommand()) + c, fs = utils.AddCommand(cmd, sharePointRestoreCmd(), utils.MarkPreReleaseCommand()) c.Use = c.Use + " " + sharePointServiceCommandUseSuffix diff --git a/src/cli/utils/utils.go b/src/cli/utils/utils.go index 0dc43d079..029f9b2bf 100644 --- a/src/cli/utils/utils.go +++ b/src/cli/utils/utils.go @@ -59,7 +59,8 @@ func HasNoFlagsAndShownHelp(cmd *cobra.Command) bool { } type cmdCfg struct { - hidden bool + hidden bool + preRelese bool } type cmdOpt func(*cmdCfg) @@ -76,6 +77,13 @@ func HideCommand() cmdOpt { } } +func MarkPreReleaseCommand() cmdOpt { + return func(cc *cmdCfg) { + cc.hidden = true + cc.preRelese = true + } +} + // AddCommand adds a clone of the subCommand to the parent, // and returns both the clone and its pflags. func AddCommand(parent, c *cobra.Command, opts ...cmdOpt) (*cobra.Command, *pflag.FlagSet) { @@ -85,6 +93,14 @@ func AddCommand(parent, c *cobra.Command, opts ...cmdOpt) (*cobra.Command, *pfla parent.AddCommand(c) c.Hidden = cc.hidden + if cc.preRelese { + // There is a default deprecated message that always shows so we do some terminal magic to overwrite it + c.Deprecated = "\n\033[1F\033[K" + + "==================================================================================================\n" + + "\tWARNING!!! THIS IS A PRE-RELEASE COMMAND THAT MAY NOT FUNCTION PROPERLY, OR AT ALL\n" + + "==================================================================================================\n" + } + c.Flags().SortFlags = false return c, c.Flags()