@@ -94,23 +94,28 @@ func runCLI(args []string) int {
9494 return 2
9595 }
9696
97- commands := map [string ]func (){
97+ remainingArgs := mainFlagSet .Args ()
98+
99+ commands := map [string ]func () int {
98100 "ability" : utils .HandleCommandOutput (ability .AbilityCommand ),
99101 "move" : utils .HandleCommandOutput (move .MoveCommand ),
100102 "natures" : utils .HandleCommandOutput (natures .NaturesCommand ),
101103 "pokemon" : utils .HandleCommandOutput (pokemon .PokemonCommand ),
102104 "types" : utils .HandleCommandOutput (types .TypesCommand ),
103- "search" : search .SearchCommand ,
105+ "search" : func () int {
106+ search .SearchCommand ()
107+ return 0
108+ },
104109 }
105110
106111 cmdArg := ""
107- if len (os . Args ) >= 2 {
108- cmdArg = os . Args [ 1 ]
112+ if len (remainingArgs ) >= 1 {
113+ cmdArg = remainingArgs [ 0 ]
109114 }
110115 cmdFunc , exists := commands [cmdArg ]
111116
112117 switch {
113- case len (os . Args ) < 2 :
118+ case len (remainingArgs ) == 0 && ! * latestFlag && ! * shortLatestFlag && ! * currentVersionFlag && ! * shortCurrentVersionFlag :
114119 mainFlagSet .Usage ()
115120 return 1
116121 case * latestFlag || * shortLatestFlag :
@@ -120,13 +125,11 @@ func runCLI(args []string) int {
120125 currentVersion ()
121126 return 0
122127 case exists :
123- cmdFunc ()
124- return 0
128+ return cmdFunc ()
125129 default :
126- command := os .Args [1 ]
127130 errMessage := styling .ErrorBorder .Render (
128131 styling .ErrorColor .Render ("Error!" ),
129- fmt .Sprintf ("\n \t %-15s" , fmt .Sprintf ("'%s' is not a valid command.\n " , command )),
132+ fmt .Sprintf ("\n \t %-15s" , fmt .Sprintf ("'%s' is not a valid command.\n " , cmdArg )),
130133 styling .StyleBold .Render ("\n Commands:" ),
131134 fmt .Sprintf ("\n \t %-15s %s" , "ability" , "Get details about an ability" ),
132135 fmt .Sprintf ("\n \t %-15s %s" , "move" , "Get details about a move" ),
@@ -138,7 +141,6 @@ func runCLI(args []string) int {
138141 )
139142 output .WriteString (errMessage )
140143
141- // This would typically be returned in a function or passed to something else
142144 fmt .Println (output .String ())
143145
144146 return 1
0 commit comments