wip
This commit is contained in:
parent
f19567f8ff
commit
b1734fcfbd
|
@ -1,54 +1,30 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/urfave/cli/v2"
|
||||
"go-mod.ewintr.nl/planner/item"
|
||||
"go-mod.ewintr.nl/planner/plan/storage"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrInvalidArg = errors.New("invalid argument")
|
||||
)
|
||||
|
||||
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,
|
||||
},
|
||||
&Flag{
|
||||
Name: "on",
|
||||
Short: "o",
|
||||
Description: "The date, in YYYY-MM-DD format",
|
||||
Required: true,
|
||||
},
|
||||
&Flag{
|
||||
Name: "at",
|
||||
Short: "a",
|
||||
Description: "The time, in HH:MM format. If omitted, the event will last the whole day",
|
||||
},
|
||||
&Flag{
|
||||
Name: "for",
|
||||
Short: "f",
|
||||
Description: "The duration, in show format (e.g. 1h30m)",
|
||||
},
|
||||
},
|
||||
type AddCmd struct {
|
||||
localIDRepo storage.LocalID
|
||||
eventRepo storage.Event
|
||||
syncRepo storage.Sync
|
||||
}
|
||||
|
||||
func NewAddCmd(localRepo storage.LocalID, eventRepo storage.Event, syncRepo storage.Sync) *cli.Command {
|
||||
AddCmd.Action = func(cCtx *cli.Context) error {
|
||||
return Add(localRepo, eventRepo, syncRepo, cCtx.String("name"), cCtx.String("on"), cCtx.String("at"), cCtx.String("for"))
|
||||
func NewAddCmd(localRepo storage.LocalID, eventRepo storage.Event, syncRepo storage.Sync) Command {
|
||||
return &AddCmd{
|
||||
localIDRepo: localRepo,
|
||||
eventRepo: eventRepo,
|
||||
syncRepo: syncRepo,
|
||||
}
|
||||
return AddCmd
|
||||
}
|
||||
|
||||
func (add *AddCmd) Do(args []string) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func Add(localIDRepo storage.LocalID, eventRepo storage.Event, syncRepo storage.Sync, nameStr, onStr, atStr, frStr string) error {
|
||||
|
|
|
@ -1,56 +1,32 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type CommandType string
|
||||
|
||||
const (
|
||||
Single CommandType = "single"
|
||||
Collection CommandType = "collection"
|
||||
var (
|
||||
ErrInvalidArg = errors.New("invalid argument")
|
||||
)
|
||||
|
||||
type Flag struct {
|
||||
Name string
|
||||
Short string
|
||||
Description string
|
||||
Required bool
|
||||
}
|
||||
|
||||
type Command struct {
|
||||
Name string
|
||||
Description string
|
||||
Flags []*Flag
|
||||
Action func([]*Flag) error
|
||||
Default bool
|
||||
type Command interface {
|
||||
Do(args []string) (bool, error)
|
||||
}
|
||||
|
||||
type CLI struct {
|
||||
CMDS []*Command
|
||||
Commands []Command
|
||||
}
|
||||
|
||||
func (cli *CLI) Run(args []string) *Command {
|
||||
if len(args) == 0 {
|
||||
args = []string{"list"}
|
||||
}
|
||||
|
||||
id, err := strconv.Atoi(args[0])
|
||||
if err == nil {
|
||||
args = args[1:]
|
||||
}
|
||||
if len(args) == 0 {
|
||||
args = []string{"show"}
|
||||
}
|
||||
|
||||
for _, c := range cli.CMDS {
|
||||
if c.Name == name {
|
||||
return c
|
||||
func (cli *CLI) Run(args []string) error {
|
||||
for _, c := range cli.Commands {
|
||||
worked, err := c.Do(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if worked {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// flags := make([]*Flag, 0, len(args))
|
||||
// for _, arg := range args {
|
||||
|
||||
// }
|
||||
return fmt.Errorf("could not find matchin command")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue