switch option update cmd

This commit is contained in:
Erik Winter 2025-01-05 09:53:56 +01:00
parent 05ad2aa0f0
commit 15b6958248
1 changed files with 12 additions and 2 deletions

View File

@ -37,10 +37,20 @@ func NewUpdateArgs() UpdateArgs {
} }
func (ua UpdateArgs) Parse(main []string, fields map[string]string) (Command, error) { func (ua UpdateArgs) Parse(main []string, fields map[string]string) (Command, error) {
if len(main) < 2 || main[0] != "update" { if len(main) < 2 {
return nil, ErrWrongCommand return nil, ErrWrongCommand
} }
localID, err := strconv.Atoi(main[1]) aliases := []string{"u", "update"}
var localIDStr string
switch {
case slices.Contains(aliases, main[0]):
localIDStr = main[1]
case slices.Contains(aliases, main[1]):
localIDStr = main[0]
default:
return nil, ErrWrongCommand
}
localID, err := strconv.Atoi(localIDStr)
if err != nil { if err != nil {
return nil, fmt.Errorf("not a local id: %v", main[1]) return nil, fmt.Errorf("not a local id: %v", main[1])
} }