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

View File

@ -1,10 +1,48 @@
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 {
Name string
Type CommandType
Description string
Flags []*Flag
Action func([]*Flag) error
}
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)
}
}