Skip to content

Commit 564a054

Browse files
committed
feat: enable specification of module use
This varies based on whether the module is used as a root command, or a subcommand in another command. Leave the decision up to the user.
1 parent e553a45 commit 564a054

File tree

4 files changed

+7
-13
lines changed

4 files changed

+7
-13
lines changed

aipcli/compilerconfig.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ type CompilerConfig struct {
1212
DefaultHost string
1313
Root string
1414
GoogleCloudIdentityTokens bool
15-
Main bool
1615
}
1716

1817
func (c *CompilerConfig) DefaultAddress() (string, bool) {
@@ -25,7 +24,6 @@ func (c *CompilerConfig) AddToFlagSet(flags *pflag.FlagSet) {
2524
flags.Var(stringStringMap{value: c.Hosts}, "hosts", "mapping from alias to host")
2625
flags.StringVar(&c.DefaultHost, "default_host", "", "default host override")
2726
flags.StringVar(&c.Root, "root", "", "root command")
28-
flags.BoolVar(&c.Main, "main", false, "write default root command main.go")
2927
flags.BoolVar(&c.GoogleCloudIdentityTokens, "gcloud_identity_tokens", false, "use gcloud to print identity tokens")
3028
}
3129

@@ -37,9 +35,6 @@ func (c *CompilerConfig) Validate() error {
3735
}
3836
return fmt.Errorf("default_host (%s) must be one of hosts (%s)", c.DefaultHost, strings.Join(hosts, ","))
3937
}
40-
if c.Main && c.Root == "" {
41-
return fmt.Errorf("main option requires root option")
42-
}
4338
return nil
4439
}
4540

cmd/examplectl/gen/module.go renamed to cmd/examplectl/gen/root.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/examplectl/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
func main() {
11-
if err := examplectl.NewModuleCommand().Execute(); err != nil {
11+
if err := examplectl.NewModuleCommand("examplectl").Execute(); err != nil {
1212
_, _ = fmt.Fprintln(os.Stderr, err)
1313
os.Exit(1)
1414
}

internal/gencli/run.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package gencli
33
import (
44
"fmt"
55
"path"
6-
"strconv"
76
"strings"
87

98
"go.einride.tech/aip-cli/aipcli"
@@ -43,7 +42,7 @@ func generateRootModuleFile(gen *protogen.Plugin, config aipcli.CompilerConfig)
4342
if !ok {
4443
return fmt.Errorf("param root requires param module to be provided")
4544
}
46-
g := gen.NewGeneratedFile(path.Join(module, "module.go"), "")
45+
g := gen.NewGeneratedFile(path.Join(module, "root.go"), "")
4746
generateGeneratedFileHeader(g)
4847
g.P("package ", config.Root)
4948
cobraCommand := g.QualifiedGoIdent(protogen.GoIdent{
@@ -59,9 +58,9 @@ func generateRootModuleFile(gen *protogen.Plugin, config aipcli.CompilerConfig)
5958
GoName: "NewModuleCommand",
6059
})
6160
g.P()
62-
g.P("func NewModuleCommand() *", cobraCommand, " {")
61+
g.P("func NewModuleCommand(use string) *", cobraCommand, " {")
6362
g.P("return ", aipCLINewModuleCommand, "(")
64-
g.P(strconv.Quote(config.Root), ",")
63+
g.P("use,")
6564
g.P("&", cliConfig, "{")
6665
g.P("Compiler: ", fmt.Sprintf("%#v", config), ",")
6766
g.P("},")

0 commit comments

Comments
 (0)