1919import java .io .PrintStream ;
2020import java .util .ArrayList ;
2121import java .util .Arrays ;
22+ import java .util .Iterator ;
2223import java .util .LinkedHashMap ;
2324import java .util .List ;
2425import java .util .Map ;
26+ import java .util .NoSuchElementException ;
2527
2628/**
2729 * Command-line entry point, built as an uber-jar. Evaluates a single string {@code --state}
@@ -105,8 +107,7 @@ private static ApiKey loadApiKey(URI endpoint) throws IOException {
105107
106108 /** The evaluate-and-print flow, taking an already-built client so it's testable without a
107109 * network call. */
108- static int run (TypeSafeClient client , Codec codec , ParsedArgs parsed , PrintStream out , PrintStream err )
109- throws Exception {
110+ static int run (TypeSafeClient client , Codec codec , ParsedArgs parsed , PrintStream out , PrintStream err ) {
110111 EvaluateRequest request = EvaluateRequest .of (Content .text (parsed .state ()), parsed .model (), parsed .questions ());
111112
112113 if (parsed .verbose ()) {
@@ -155,19 +156,20 @@ static ParsedArgs parse(String[] args) {
155156 URI endpoint = null ;
156157
157158 try {
158- for (int i = 0 ; i < args .length ; i ++) {
159- String flag = args [i ];
159+ Iterator <String > it = List .of (args ).iterator ();
160+ while (it .hasNext ()) {
161+ String flag = it .next ();
160162
161163 switch (flag ) {
162164 case "--verbose" -> verbose = true ;
163165 case "--timing" -> timing = true ;
164- case "--state" -> state = args [++ i ] ;
165- case "--model" -> model = new Model (args [++ i ] );
166- case "--endpoint" -> endpoint = URI .create (args [++ i ] );
167- case "--min" -> minSpecs .add (args [++ i ] );
168- case "--print" -> printNames .add (args [++ i ] );
166+ case "--state" -> state = it . next () ;
167+ case "--model" -> model = new Model (it . next () );
168+ case "--endpoint" -> endpoint = URI .create (it . next () );
169+ case "--min" -> minSpecs .add (it . next () );
170+ case "--print" -> printNames .add (it . next () );
169171 case "--noul" , "--choice" , "--score" -> {
170- String value = args [++ i ] ;
172+ String value = it . next () ;
171173 int eq = value .indexOf ('=' );
172174 String name = eq >= 0 ? value .substring (0 , eq ) : flag .substring (2 );
173175 String rest = eq >= 0 ? value .substring (eq + 1 ) : value ;
@@ -176,7 +178,7 @@ static ParsedArgs parse(String[] args) {
176178 default -> throw new IllegalArgumentException ("Unknown flag: " + flag );
177179 }
178180 }
179- } catch (ArrayIndexOutOfBoundsException e ) {
181+ } catch (NoSuchElementException e ) {
180182 throw new IllegalArgumentException ("Missing value for " + args [args .length - 1 ]);
181183 }
182184
@@ -192,7 +194,7 @@ static ParsedArgs parse(String[] args) {
192194
193195 static String answerValue (EvaluateResponse response , String name ) {
194196 return switch (response .answers ().get (name )) {
195- case Answer .Noul n -> String .valueOf (n . noul () );
197+ case Answer .Noul ( var noul ) -> String .valueOf (noul );
196198 case Answer .Choice c -> c .choice ();
197199 case Answer .Score s -> String .valueOf (s .score ());
198200 case null -> throw new IllegalArgumentException ("No such answer: " + name );
@@ -206,7 +208,7 @@ static List<String> minFailures(EvaluateResponse response, List<String> minSpecs
206208 String name = spec .substring (0 , eq );
207209 double min = Double .parseDouble (spec .substring (eq + 1 ));
208210 double value = switch (response .answers ().get (name )) {
209- case Answer .Noul n -> n . noul () ;
211+ case Answer .Noul ( var noul ) -> noul ;
210212 case Answer .Score s -> s .score ();
211213 case null -> throw new IllegalArgumentException ("No such answer: " + name );
212214 default -> throw new IllegalArgumentException (
0 commit comments