planner/plan/command/command.go

49 lines
790 B
Go
Raw Normal View History

2024-10-29 07:22:28 +01:00
package command
2024-10-30 07:25:05 +01:00
import "strconv"
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
Type CommandType
Description string
Flags []*Flag
Action func([]*Flag) error
2024-10-29 07:22:28 +01:00
}
type CLI struct {
2024-10-30 07:25:05 +01:00
single []*Command
collection []*Command
2024-10-29 07:22:28 +01:00
}
2024-10-30 07:25:05 +01:00
func (cli *CLI) Add(cmd *Command) {
if cmd.Type == Single {
cli.single = append(cli.single, cmd)
return
}
cli.collection = append(cli.collection, cmd)
}
func ParseArg(args []string) Command {
cmd, cmdArgs := args[0], args[1:]
id, err := strconv.Atoi(cmd)
if err == nil {
return parseTaskCommand(id, cmdArgs, conf)
}
}