diff --git a/pkg/cmd/grafana/main.go b/pkg/cmd/grafana/main.go index 9985f6e64e8..e9003dd078a 100644 --- a/pkg/cmd/grafana/main.go +++ b/pkg/cmd/grafana/main.go @@ -20,7 +20,18 @@ var buildBranch = "main" var buildstamp string func main() { - app := &cli.App{ + app := MainApp() + + if err := app.Run(os.Args); err != nil { + fmt.Printf("%s: %s %s\n", color.RedString("Error"), color.RedString("✗"), err) + os.Exit(1) + } + + os.Exit(0) +} + +func MainApp() *cli.App { + return &cli.App{ Name: "grafana", Usage: "Grafana server and command line interface", Authors: []*cli.Author{ @@ -52,18 +63,10 @@ func main() { return nil }, }, - gsrv.ServerCommand(version, commit, enterpriseCommit, buildBranch, buildstamp), }, CommandNotFound: cmdNotFound, EnableBashCompletion: true, } - - if err := app.Run(os.Args); err != nil { - fmt.Printf("%s: %s %s\n", color.RedString("Error"), color.RedString("✗"), err) - os.Exit(1) - } - - os.Exit(0) } func cmdNotFound(c *cli.Context, command string) { diff --git a/pkg/cmd/grafana/main_test.go b/pkg/cmd/grafana/main_test.go new file mode 100644 index 00000000000..0ec0d980643 --- /dev/null +++ b/pkg/cmd/grafana/main_test.go @@ -0,0 +1,16 @@ +package main + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestMainApp_NoDuplicateSubcommands(t *testing.T) { + app := MainApp() + found := map[string]bool{} + for _, cmd := range app.Commands { + require.False(t, found[cmd.Name], "command %q registered twice", cmd.Name) + found[cmd.Name] = true + } +}