This commit is contained in:
Erik Winter 2024-10-31 07:26:03 +01:00
parent bca0ac37c4
commit 6edfa5c461
1 changed files with 22 additions and 15 deletions

View File

@ -1,6 +1,8 @@
package command package command
import "strconv" import (
"strconv"
)
type CommandType string type CommandType string
@ -18,6 +20,7 @@ type Flag struct {
type Command struct { type Command struct {
Name string Name string
LocalID int
Type CommandType Type CommandType
Description string Description string
Flags []*Flag Flags []*Flag
@ -25,24 +28,28 @@ type Command struct {
} }
type CLI struct { type CLI struct {
single []*Command cmds []*Command
collection []*Command
} }
func (cli *CLI) Add(cmd *Command) { func (cli *CLI) ParseArg(args []string) *Command {
if cmd.Type == Single { name, args := args[0], args[1:]
cli.single = append(cli.single, cmd)
return
}
cli.collection = append(cli.collection, cmd)
}
func ParseArg(args []string) Command { cmds := cli.collection
cmd, cmdArgs := args[0], args[1:] id, err := strconv.Atoi(name)
id, err := strconv.Atoi(cmd)
if err == nil { if err == nil {
return parseTaskCommand(id, cmdArgs, conf) name, args = args[0], args[1:]
cmds = cli.single
} }
for _, c := range cmds {
if c.Name == name {
c.LocalID = id
return c
}
}
flags := make([]*Flag, 0, len(args))
for _, arg := range args {
}
} }