-
Notifications
You must be signed in to change notification settings - Fork 787
/
experimental.go
74 lines (64 loc) · 1.98 KB
/
experimental.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package experimental
import (
"fmt"
"strings"
"github.com/jenkins-x/jx/v2/pkg/util"
"github.com/spf13/cobra"
)
// alphaCommands list of deprecated commands along with some more deprecation details
var alphaCommands = map[string]info{
"step create helmfile": {
info: "** EXPERIMENTAL COMMAND ** Generates a helmfile from a jx-apps.yml see enhancement https://github.com/jenkins-x/enhancements/pull/1",
createdDate: "Jan 28 2020",
},
}
// betaCommands list of deprecated commands along with some more deprecation details
var betaCommands = map[string]info{}
// info keeps experiment details related to a command
type info struct {
createdDate string
info string
}
// AlphaCommands runs recursively over all commands and set the message
// on every command defined in the commands map.
func AlphaCommands(cmd *cobra.Command) {
path := commandPath(cmd)
if alpha, ok := alphaCommands[path]; ok {
msg := fmt.Sprintf("Alpha command, expect this to change or be removed, created: %s", alpha.createdDate)
cmd.Short = util.ColorWarning(msg)
cmd.Long = util.ColorWarning(msg + "\n" + alpha.info)
}
if !cmd.HasSubCommands() {
return
}
for _, c := range cmd.Commands() {
AlphaCommands(c)
}
}
// BetaCommands runs recursively over all commands and set the message
// on every command defined in the commands map.
func BetaCommands(cmd *cobra.Command) {
path := commandPath(cmd)
if beta, ok := betaCommands[path]; ok {
msg := fmt.Sprintf("Beta command, still experimental but maturing towards being GA, created: %s", beta.createdDate)
cmd.Short = util.ColorWarning(msg)
cmd.Long = util.ColorWarning(msg + "\n" + beta.info)
}
if !cmd.HasSubCommands() {
return
}
for _, c := range cmd.Commands() {
BetaCommands(c)
}
}
func commandPath(cmd *cobra.Command) string {
parentText := ""
parent := cmd.Parent()
if parent != nil {
parentText = commandPath(parent)
if parentText != "" {
parentText += " "
}
}
return strings.TrimPrefix(parentText, "jx ") + cmd.Name()
}