-
Notifications
You must be signed in to change notification settings - Fork 69
/
stackset.go
60 lines (45 loc) · 2.06 KB
/
stackset.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
package stackset
import (
"github.com/aws-cloudformation/rain/internal/config"
"github.com/aws-cloudformation/rain/internal/console"
"github.com/spf13/cobra"
)
const usageTemplate = `Usage:{{if .Runnable}}
<cyan>{{.UseLine}}</>{{end}}{{if .HasAvailableSubCommands}}
<cyan>{{.CommandPath}}</> [<gray>command</>]{{end}}{{if gt (len .Aliases) 0}}
Aliases: {{.NameAndAliases}}{{end}}{{if .HasExample}}
Examples:
{{.Example}}{{end}}{{if .HasAvailableSubCommands}}
Available Commands:{{range .Commands}}{{if (or .IsAvailableCommand (eq .Name "help"))}}
<cyan>{{rpad .Name .NamePadding }}</> {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}}
Flags:
{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}}
Global Flags:
{{.InheritedFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasHelpSubCommands}}
Additional help topics:{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}}
{{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableSubCommands}}
Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}}
`
func addCommand(profileOptions bool, c *cobra.Command) {
if profileOptions {
c.Flags().StringVarP(&config.Profile, "profile", "p", "", "AWS profile name; read from the AWS CLI configuration file")
c.Flags().StringVarP(&config.Region, "region", "r", "", "AWS region to use")
}
StackSetCmd.AddCommand(c)
}
var StackSetCmd = &cobra.Command{
Use: "stackset <stack_set command>",
Short: "This command manipulates stack sets.",
Long: "This command manipulates stack sets. It has no action if specific stack set command is not added.",
}
func init() {
addCommand(true, StackSetLsCmd)
addCommand(true, StackSetDeployCmd)
addCommand(true, StackSetRmCmd)
oldUsageFunc := StackSetCmd.UsageFunc()
StackSetCmd.SetUsageFunc(func(c *cobra.Command) error {
StackSetCmd.SetUsageTemplate(console.Sprint(usageTemplate))
return oldUsageFunc(c)
})
StackSetCmd.PersistentFlags().BoolVarP(&console.NoColour, "no-colour", "", false, "Disable colour output")
}