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?

- [ ]  Yes, it's included
- [ ] 🕐 Yes, but in a later PR
- [x]  No 

## Type of change

<!--- Please check the type of change your PR introduces: --->
- [x] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Test
- [ ] 💻 CI/Deployment
- [ ] 🧹 Tech Debt/Cleanup

## Issue(s)

## Test Plan

<!-- How will this be tested prior to merging.-->
- [x] 💪 Manual
- [ ]  Unit test
- [ ] 💚 E2E
This commit is contained in:
Georgi Matev 2023-01-27 12:47:15 -08:00 committed by GitHub
parent 09821f2f0d
commit 3e106dbac8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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()