planner/plan/command/command.go

57 lines
798 B
Go
Raw Normal View History

2024-10-29 07:22:28 +01:00
package command
2024-10-31 07:26:03 +01:00
import (
"strconv"
)
2024-10-30 07:25:05 +01:00
type CommandType string
const (
Single CommandType = "single"
Collection CommandType = "collection"
)
type Flag struct {
Name string
Short string
Description string
Required bool
}
2024-10-29 07:22:28 +01:00
type Command struct {
2024-10-30 07:25:05 +01:00
Name string
Description string
Flags []*Flag
Action func([]*Flag) error
2024-11-01 07:31:21 +01:00
Default bool
2024-10-29 07:22:28 +01:00
}
type CLI struct {
2024-11-01 07:31:21 +01:00
CMDS []*Command
2024-10-30 07:25:05 +01:00
}
2024-11-01 07:31:21 +01:00
func (cli *CLI) Run(args []string) *Command {
if len(args) == 0 {
args = []string{"list"}
}
2024-10-30 07:25:05 +01:00
2024-11-01 07:31:21 +01:00
id, err := strconv.Atoi(args[0])
2024-10-30 07:25:05 +01:00
if err == nil {
2024-11-01 07:31:21 +01:00
args = args[1:]
}
if len(args) == 0 {
args = []string{"show"}
2024-10-30 07:25:05 +01:00
}
2024-11-01 07:31:21 +01:00
for _, c := range cli.CMDS {
2024-10-31 07:26:03 +01:00
if c.Name == name {
return c
}
}
2024-11-01 07:31:21 +01:00
// flags := make([]*Flag, 0, len(args))
// for _, arg := range args {
2024-10-31 07:26:03 +01:00
2024-11-01 07:31:21 +01:00
// }
2024-10-30 07:25:05 +01:00
}