mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
Mark experimental flags in --help
Prior to this commit, experimental flags were not distinguishable from regular flags in `--help` Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
@ -1,6 +1,10 @@
|
||||
package cobrautil
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
// HideInheritedFlags hides inherited flags
|
||||
func HideInheritedFlags(cmd *cobra.Command, hidden ...string) {
|
||||
@ -12,3 +16,38 @@ func HideInheritedFlags(cmd *cobra.Command, hidden ...string) {
|
||||
_ = cmd.Flags().MarkHidden(h)
|
||||
}
|
||||
}
|
||||
|
||||
const annotationExperimentalCLI = "experimentalCLI"
|
||||
|
||||
func MarkFlagExperimental(f *pflag.Flag) {
|
||||
if _, ok := f.Annotations[annotationExperimentalCLI]; ok {
|
||||
return
|
||||
}
|
||||
if f.Annotations == nil {
|
||||
f.Annotations = make(map[string][]string)
|
||||
}
|
||||
f.Annotations[annotationExperimentalCLI] = nil
|
||||
f.Usage += " (EXPERIMENTAL)"
|
||||
}
|
||||
|
||||
func MarkFlagsExperimental(fs *pflag.FlagSet, names ...string) {
|
||||
for _, name := range names {
|
||||
f := fs.Lookup(name)
|
||||
if f == nil {
|
||||
logrus.Warningf("Unknown flag name %q", name)
|
||||
continue
|
||||
}
|
||||
MarkFlagExperimental(f)
|
||||
}
|
||||
}
|
||||
|
||||
func MarkCommandExperimental(c *cobra.Command) {
|
||||
if _, ok := c.Annotations[annotationExperimentalCLI]; ok {
|
||||
return
|
||||
}
|
||||
if c.Annotations == nil {
|
||||
c.Annotations = make(map[string]string)
|
||||
}
|
||||
c.Annotations[annotationExperimentalCLI] = ""
|
||||
c.Short += " (EXPERIMENTAL)"
|
||||
}
|
||||
|
Reference in New Issue
Block a user