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:
@@ -20,7 +20,18 @@ var buildBranch = "main"
|
|||||||
var buildstamp string
|
var buildstamp string
|
||||||
|
|
||||||
func main() {
|
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",
|
Name: "grafana",
|
||||||
Usage: "Grafana server and command line interface",
|
Usage: "Grafana server and command line interface",
|
||||||
Authors: []*cli.Author{
|
Authors: []*cli.Author{
|
||||||
@@ -52,18 +63,10 @@ func main() {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
gsrv.ServerCommand(version, commit, enterpriseCommit, buildBranch, buildstamp),
|
|
||||||
},
|
},
|
||||||
CommandNotFound: cmdNotFound,
|
CommandNotFound: cmdNotFound,
|
||||||
EnableBashCompletion: true,
|
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) {
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user