diff --git a/plan/command/add.go b/plan/command/add.go index 8f07e46..c6765ad 100644 --- a/plan/command/add.go +++ b/plan/command/add.go @@ -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)", }, }, } diff --git a/plan/command/command.go b/plan/command/command.go index 2d9657c..30bac06 100644 --- a/plan/command/command.go +++ b/plan/command/command.go @@ -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) + } + +}