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 package common
import ( import (
"flag"
"fmt" "fmt"
"log"
) )
type Args struct { type Args struct {
@ -20,20 +22,33 @@ const (
CommandDebugListMTrace = "debug-ls-mtrace" 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 { func validateArg(arg string) error {
switch cmd { for _, v := range ValidCommands {
case CommandStart, if arg == v {
CommandValidate, return nil
CommandListConfigs, }
CommandListRoutes,
CommandListIcons,
CommandReload,
CommandDebugListEntries,
CommandDebugListProviders,
CommandDebugListMTrace:
return true
} }
return fmt.Errorf("invalid command %q", arg) 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
}