mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-09 04:52:35 +02:00
fix args.go affected from cherry-pick
This commit is contained in:
parent
b2a6a20f10
commit
e6f77376b9
1 changed files with 28 additions and 13 deletions
|
@ -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
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue