This commit is contained in:
Erik Winter 2024-10-30 07:25:05 +01:00
parent 108f88b1c3
commit bca0ac37c4
2 changed files with 62 additions and 24 deletions

View File

@ -15,31 +15,31 @@ var (
ErrInvalidArg = errors.New("invalid argument") ErrInvalidArg = errors.New("invalid argument")
) )
var AddCmd = &cli.Command{ var AddCmd = &Command{
Name: "add", Name: "add",
Usage: "Add a new event", Description: "Add a new event",
Flags: []cli.Flag{ Flags: []*Flag{
&cli.StringFlag{ &Flag{
Name: "name", Name: "name",
Aliases: []string{"n"}, Short: "n",
Usage: "The event that will happen", Description: "The event that will happen",
Required: true, Required: true,
}, },
&cli.StringFlag{ &Flag{
Name: "on", Name: "on",
Aliases: []string{"o"}, Short: "o",
Usage: "The date, in YYYY-MM-DD format", Description: "The date, in YYYY-MM-DD format",
Required: true, Required: true,
}, },
&cli.StringFlag{ &Flag{
Name: "at", Name: "at",
Aliases: []string{"a"}, Short: "a",
Usage: "The time, in HH:MM format. If omitted, the event will last the whole day", Description: "The time, in HH:MM format. If omitted, the event will last the whole day",
}, },
&cli.StringFlag{ &Flag{
Name: "for", Name: "for",
Aliases: []string{"f"}, Short: "f",
Usage: "The duration, in show format (e.g. 1h30m)", Description: "The duration, in show format (e.g. 1h30m)",
}, },
}, },
} }

View File

@ -1,10 +1,48 @@
package command package command
import "strconv"
type CommandType string
const (
Single CommandType = "single"
Collection CommandType = "collection"
)
type Flag struct {
Name string
Short string
Description string
Required bool
}
type Command struct { type Command struct {
Name string
Type CommandType
Description string
Flags []*Flag
Action func([]*Flag) error
} }
type CLI struct { type CLI struct {
cmds []Command single []*Command
collection []*Command
} }
func ShiftArg() {} 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)
}
}