@@ -33,36 +33,7 @@ func CallCmd() *cobra.Command {
3333 os .Exit (1 )
3434 }
3535
36- cmdArgs := args
37- parsedArgs := []string {}
38- entityName := ""
39-
40- i := 0
41- entityExtracted := false
42-
43- for i < len (cmdArgs ) {
44- switch {
45- case (cmdArgs [i ] == FlagFormat || cmdArgs [i ] == FlagFormatShort ) && i + 1 < len (cmdArgs ):
46- FormatOption = cmdArgs [i + 1 ]
47- i += 2
48- case (cmdArgs [i ] == FlagParams || cmdArgs [i ] == FlagParamsShort ) && i + 1 < len (cmdArgs ):
49- ParamsString = cmdArgs [i + 1 ]
50- i += 2
51- case ! entityExtracted :
52- entityName = cmdArgs [i ]
53- entityExtracted = true
54- i ++
55- case cmdArgs [i ] == FlagServerLogs :
56- ShowServerLogs = true
57- i ++
58- case cmdArgs [i ] == FlagVerbose || cmdArgs [i ] == FlagVerboseShort :
59- Verbose = true
60- i ++
61- default :
62- parsedArgs = append (parsedArgs , cmdArgs [i ])
63- i ++
64- }
65- }
36+ parsedArgs , entityName := parseCallArguments (args )
6637
6738 if entityName == "" {
6839 fmt .Fprintln (os .Stderr , "Error: entity name is required" )
@@ -151,3 +122,38 @@ func CallCmd() *cobra.Command {
151122 },
152123 }
153124}
125+
126+ // fix cyclomatic complexity
127+ func parseCallArguments (args []string ) ([]string , string ) {
128+ cmdArgs := args
129+ parsedArgs := []string {}
130+ entityName := ""
131+
132+ i := 0
133+ entityExtracted := false
134+
135+ for i < len (cmdArgs ) {
136+ switch {
137+ case (cmdArgs [i ] == FlagFormat || cmdArgs [i ] == FlagFormatShort ) && i + 1 < len (cmdArgs ):
138+ FormatOption = cmdArgs [i + 1 ]
139+ i += 2
140+ case (cmdArgs [i ] == FlagParams || cmdArgs [i ] == FlagParamsShort ) && i + 1 < len (cmdArgs ):
141+ ParamsString = cmdArgs [i + 1 ]
142+ i += 2
143+ case ! entityExtracted :
144+ entityName = cmdArgs [i ]
145+ entityExtracted = true
146+ i ++
147+ case cmdArgs [i ] == FlagServerLogs :
148+ ShowServerLogs = true
149+ i ++
150+ case cmdArgs [i ] == FlagVerbose || cmdArgs [i ] == FlagVerboseShort :
151+ Verbose = true
152+ i ++
153+ default :
154+ parsedArgs = append (parsedArgs , cmdArgs [i ])
155+ i ++
156+ }
157+ }
158+ return parsedArgs , entityName
159+ }
0 commit comments