aboutsummaryrefslogtreecommitdiffstats
path: root/src/ArgParser.java
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2013-06-18 15:51:23 +0200
committerMattias Andrée <maandree@operamail.com>2013-06-18 15:51:23 +0200
commit92025a894b9357e75c7cb06164cd4f61185f1751 (patch)
tree94f15085f2e30afbf66a65f3abf432e9eddd421d /src/ArgParser.java
parentimplement help for bash version (diff)
downloadargparser-92025a894b9357e75c7cb06164cd4f61185f1751.tar.gz
argparser-92025a894b9357e75c7cb06164cd4f61185f1751.tar.bz2
argparser-92025a894b9357e75c7cb06164cd4f61185f1751.tar.xz
misc
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/ArgParser.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/ArgParser.java b/src/ArgParser.java
index 6ea7e65..e75ba91 100644
--- a/src/ArgParser.java
+++ b/src/ArgParser.java
@@ -164,6 +164,11 @@ public class ArgParser
public int unrecognisedCount = 0;
/**
+ * The concatination of {@link #files} with blankspaces as delimiters, {@code null} if no files
+ */
+ public String message = null;
+
+ /**
* Options, in order
*/
private final ArrayList<Option> options = new ArrayList<Option>();
@@ -1002,6 +1007,62 @@ public class ArgParser
this.files.add(arg);
}
+ int i = 0, n = optqueue.size();
+ while (i < n)
+ {
+ final String opt = this.optmap.get(optqueue.get(i)).standard;
+ final String arg = argqueue.size() > i ? argqueue.get(i) : null;
+ i++;
+ if (this.opts.get(opt) == null)
+ this.opts.put(opt, new String[] {});
+ if (argqueue.size() >= i)
+ this.opts.put(opt, append(this.opts.get(opt), arg));
+ }
+
+ for (final Option opt : this.options)
+ if (opt.getClass() == Variadic.class)
+ { final String[] varopt = this.opts.get(opt.standard);
+ if (varopt != null)
+ {
+ final String[] additional = new String[this.files.size()];
+ this.files.toArray(additional);
+ if (varopt[0] == null)
+ this.opts.put(opt.standard, additional);
+ else
+ this.opts.put(opt.standard, append(varopt, additional));
+ this.files.clear();
+ break;
+ } }
+
+ final StringBuilder sb = new StringBuilder();
+ for (final String file : this.files)
+ { sb.append(' ');
+ sb.append(file);
+ }
+ this.message = sb.toString().substring(1);
+
+ if (this.unrecognisedCount > 5)
+ { int more = this.unrecognisedCount - 5;
+ this.print(this.program + ": warning: " + more + " more unrecognised ");
+ this.println(more == 1 ? "option" : "options");
+ }
+
+ return rc;
+ }
+
+
+ /**
+ * Create a new identical array, except with extra items at the end
+ *
+ * @param array The array
+ * @param items The new items
+ * @return The new array
+ */
+ private String[] append(final String[] array, final String... items)
+ {
+ final String[] rc = new String[array.length + items.length];
+ System.arraycopy(array, 0, rc, 0, array.length);
+ System.arraycopy(items, 0, rc, array.length, items.length);
return rc;
}