...
1
2 package add
3
4 import (
5 "fmt"
6
7 "edge-infra.dev/pkg/edge/api/graph/model"
8 "edge-infra.dev/pkg/edge/edgecli/flagutil"
9 "edge-infra.dev/pkg/lib/cli/rags"
10 )
11
12 type CommandMutation struct {
13 CreateOperatorInterventionCommands struct {
14 model.CreateOperatorInterventionCommandResponse
15 } `graphql:"createOperatorInterventionCommands(commands: $commands)"`
16 }
17
18 func (mut CommandMutation) Errors() []*model.OperatorInterventionErrorResponse {
19 return mut.CreateOperatorInterventionCommands.Errors
20 }
21
22 type Command struct {
23
24
25 commands []string
26 }
27
28 func (cmd *Command) ShortUsageString() string {
29 return "edgeadmin operatorintervention add command [--command <command>]"
30 }
31
32 func (cmd *Command) ShortHelpString() string {
33 return "Add new commands to the database"
34 }
35
36 func (cmd *Command) LongHelpString() string {
37 return fmt.Sprintf(longHelpSingleFlagFormatString, "command")
38 }
39
40 func (cmd *Command) Flags() []*rags.Rag {
41 return []*rags.Rag{
42 {
43 Name: flagutil.OICommand,
44 Usage: "command to be added",
45 Value: &rags.StringSet{
46 Var: &cmd.commands,
47 },
48 Required: true,
49 },
50 }
51 }
52
53 func (cmd *Command) Variables() map[string]interface{} {
54 var input []model.OperatorInterventionCommandInput
55 for _, command := range cmd.commands {
56 input = append(input, model.OperatorInterventionCommandInput{
57 Name: command,
58 })
59 }
60 return map[string]interface{}{
61 "commands": input,
62 }
63 }
64
65 func (cmd *Command) Mutation() OperatorInterventionMutation {
66 return &CommandMutation{}
67 }
68
69 func (cmd *Command) ResponseType() string {
70 output := "Command"
71 if len(cmd.commands) > 1 {
72 output += "s"
73 }
74 return output
75 }
76
View as plain text