File tree Expand file tree Collapse file tree
src/main/java/net/marcellperger/mathexpr Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,4 +30,9 @@ public int getMax() {
3030 public boolean includes (int v ) {
3131 return lo <= v && v <= hi ;
3232 }
33+
34+ public String fancyRepr () {
35+ if (lo == hi ) return "exactly %d" .formatted (lo );
36+ return "%d to %d" .formatted (lo , hi );
37+ }
3338}
Original file line number Diff line number Diff line change 11package net .marcellperger .mathexpr .cli .minicli ;
22
3- import net .marcellperger .mathexpr .IntRange ;
43import net .marcellperger .mathexpr .UIntRange ;
54import net .marcellperger .mathexpr .util .Pair ;
65import net .marcellperger .mathexpr .util .Util ;
1211import java .util .HashMap ;
1312import java .util .List ;
1413import java .util .Map ;
15- import java .util .Objects ;
1614import java .util .function .Function ;
1715
1816public class MiniCLI {
@@ -124,7 +122,11 @@ public void pumpSingleArg(String arg) {
124122 }
125123
126124 public void finish () {
127- if (prev != null ) flushPrev ();
125+ if (prev != null ) flushPrev (); // TODO handle required kw-args
126+ int nArgs = positionalArgs .size ();
127+ if (!nPositionalArgs .includes (nArgs ))
128+ throw new CLIParseException ("Incorrect number of positional args (required %s, got %d)"
129+ .formatted (nPositionalArgs .fancyRepr (), nArgs ));
128130 }
129131
130132 // Makes more logical sense reading the code
@@ -153,6 +155,7 @@ private void addPositionalArg(String arg) {
153155 int maxArgc = nPositionalArgs .getMax ();
154156 if (newSize > maxArgc )
155157 throw new CLIParseException ("Too many positional args (expected max %d, got %d)" .formatted (maxArgc , newSize ));
158+ positionalArgs .add (arg );
156159 }
157160 }
158161 private enum ArgType {
You can’t perform that action at this time.
0 commit comments