package command import ( "fmt" "strings" "go-mod.ewintr.nl/planner/plan/storage" ) const ( FieldTitle = "title" FieldDate = "date" FieldTime = "time" FieldDuration = "duration" FieldRecurrer = "recurrer" ) type Dependencies struct { LocalIDRepo storage.LocalID TaskRepo storage.Task SyncRepo storage.Sync } type Command interface { Do() error } type CLI struct { Commands []Command } func (cli *CLI) Run(args []string) error { // main, flags, err := ParseFlags(args) // if err != nil { // return err // } // for _, c := range cli.Commands { // err := c.Execute(main, flags) // switch { // case errors.Is(err, ErrWrongCommand): // continue // case err != nil: // return err // default: // return nil // } // } return fmt.Errorf("could not find matching command") } func ParseFlags(args []string) ([]string, map[string]string, error) { flags := make(map[string]string) main := make([]string, 0) var inMain bool for i := 0; i < len(args); i++ { if strings.HasPrefix(args[i], "-") { inMain = false if i+1 >= len(args) { return nil, nil, fmt.Errorf("flag wihout value") } flags[strings.TrimPrefix(args[i], "-")] = args[i+1] i++ continue } if !inMain && len(main) > 0 { return nil, nil, fmt.Errorf("two mains") } inMain = true main = append(main, args[i]) } return main, flags, nil }