fix args.go affected from cherry-pick

This commit is contained in:
yusing 2025-02-18 16:35:23 +08:00
parent b2a6a20f10
commit e6f77376b9

View file

@ -1,7 +1,9 @@
package common
import (
"flag"
"fmt"
"log"
)
type Args struct {
@ -20,20 +22,33 @@ const (
CommandDebugListMTrace = "debug-ls-mtrace"
)
type MainServerCommandValidator struct{}
var ValidCommands = []string{
CommandStart,
CommandValidate,
CommandListConfigs,
CommandListRoutes,
CommandListIcons,
CommandReload,
CommandDebugListEntries,
CommandDebugListProviders,
CommandDebugListMTrace,
}
func (v MainServerCommandValidator) IsCommandValid(cmd string) bool {
switch cmd {
case CommandStart,
CommandValidate,
CommandListConfigs,
CommandListRoutes,
CommandListIcons,
CommandReload,
CommandDebugListEntries,
CommandDebugListProviders,
CommandDebugListMTrace:
return true
func validateArg(arg string) error {
for _, v := range ValidCommands {
if arg == v {
return nil
}
}
return fmt.Errorf("invalid command %q", arg)
}
func GetArgs() Args {
var args Args
flag.Parse()
args.Command = flag.Arg(0)
if err := validateArg(args.Command); err != nil {
log.Fatalf("invalid command: %s", err)
}
return args
}