@@ -34,6 +34,13 @@ import (
3434// emit the same name as their canonical subcommand.
3535const canonicalCommandAnnotation = "lstk.canonical"
3636
37+ // Command group IDs used to separate the proxy "tool" commands (aws, terraform,
38+ // cdk, sam, az) from the rest of lstk's commands in the help output.
39+ const (
40+ groupCommands = "commands"
41+ groupTools = "tools"
42+ )
43+
3744func NewRootCmd (cfg * env.Env , tel * telemetry.Client , logger log.Logger ) * cobra.Command {
3845 var firstRun bool
3946 root := & cobra.Command {
@@ -69,7 +76,12 @@ func NewRootCmd(cfg *env.Env, tel *telemetry.Client, logger log.Logger) *cobra.C
6976 root .Flags ().Lookup ("version" ).Usage = "Show version"
7077 root .SetVersionTemplate (versionLine () + "\n " )
7178
72- root .AddCommand (
79+ root .AddGroup (
80+ & cobra.Group {ID : groupCommands , Title : "Commands:" },
81+ & cobra.Group {ID : groupTools , Title : "Tools:" },
82+ )
83+
84+ commands := []* cobra.Command {
7385 newStartCmd (cfg , tel , logger ),
7486 newStopCmd (cfg , tel ),
7587 newRestartCmd (cfg , tel , logger ),
@@ -82,16 +94,33 @@ func NewRootCmd(cfg *env.Env, tel *telemetry.Client, logger log.Logger) *cobra.C
8294 newVolumeCmd (cfg ),
8395 newUpdateCmd (cfg ),
8496 newDocsCmd (),
97+ newSnapshotCmd (cfg , tel , logger ),
98+ newResetCmd (cfg ),
99+ newSaveCmd (cfg ),
100+ newLoadCmd (cfg , tel , logger ),
101+ }
102+ for _ , c := range commands {
103+ c .GroupID = groupCommands
104+ }
105+
106+ // Proxy commands that forward to a wrapped tool (AWS/Azure CLI, Terraform,
107+ // CDK, SAM) configured to target LocalStack.
108+ tools := []* cobra.Command {
85109 newAWSCmd (cfg ),
86110 newTerraformCmd (cfg , logger ),
87111 newCDKCmd (cfg , logger ),
88112 newSamCmd (cfg , logger ),
89- newSnapshotCmd (cfg , tel , logger ),
90113 newAzCmd (cfg ),
91- newResetCmd (cfg ),
92- newSaveCmd (cfg ),
93- newLoadCmd (cfg , tel , logger ),
94- )
114+ }
115+ for _ , c := range tools {
116+ c .GroupID = groupTools
117+ }
118+
119+ root .AddCommand (commands ... )
120+ root .AddCommand (tools ... )
121+
122+ root .SetHelpCommandGroupID (groupCommands )
123+ root .SetCompletionCommandGroupID (groupCommands )
95124
96125 return root
97126}
0 commit comments