-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.go
36 lines (32 loc) · 965 Bytes
/
action.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package service
import (
"fmt"
"github.com/emreodabas/kubectl-bulk/pkg/interaction"
"github.com/emreodabas/kubectl-bulk/pkg/model"
"strings"
)
func ActionSelection(arg string, command *model.Command) error {
var err error
//action time
if arg == "" {
command.Action = interaction.ShowActionList()
} else {
command.Action, err = getAction(arg)
fmt.Println("---- SELECTED ACTION ----\n---- ", command.Action.Name, " ----\n-----------------------------------------")
if err != nil {
return err
}
}
return nil
}
func getAction(action string) (model.Action, error) {
var actionMessage string
action = strings.ToLower(action)
for i := 0; i < len(model.Actionlist); i++ {
actionMessage += model.Actionlist[i].Name + " "
if strings.ToLower(model.Actionlist[i].Name) == action {
return model.Actionlist[i], nil
}
}
return model.Action{}, fmt.Errorf(action + " is not a valid action. Choose wisely one of them -> " + actionMessage)
}