mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Server: Fix 'server' subcommand double-registration (#86083)
fix 'server' subcommand double-registration Signed-off-by: Dave Henderson <dave.henderson@grafana.com>
This commit is contained in:
parent
ad8d505d81
commit
44adfea049
@ -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) {
|
||||
|
16
pkg/cmd/grafana/main_test.go
Normal file
16
pkg/cmd/grafana/main_test.go
Normal file
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user