ParsedArg(final String argument) { final QuotedStringTokenizer st = new QuotedStringTokenizer(argument, "="); if (!st.hasMoreTokens()) { throw new IllegalArgumentException(); } final String token = st.nextToken(); this.template = Options.getOptionTemplate(token); if (this.template == null) { throw new IllegalArgumentException(argument); } value = ""; if (st.hasMoreTokens()) { while (st.hasMoreTokens()) { value += st.nextToken(); if (st.hasMoreTokens()) { value += ':'; } } } else if ("boolean".equals(this.template.getType())) { value = "true"; } }
ParsedArg(final String argument) { final QuotedStringTokenizer st = new QuotedStringTokenizer(argument, "="); if (!st.hasMoreTokens()) { throw new IllegalArgumentException(); } final String token = st.nextToken(); this.template = getOptionTemplateByName(token); if (this.template == null) { throw new IllegalArgumentException(argument); } value = ""; if (st.hasMoreTokens()) { while (st.hasMoreTokens()) { value += st.nextToken(); if (st.hasMoreTokens()) { value += ':'; } } } else if ("boolean".equals(this.template.getType())) { value = "true"; } }
private void parse(final String origValue) { String value = origValue.trim(); try { value = OptionTemplate.strip(value, '{', '}'); final QuotedStringTokenizer keyValuePairs = new QuotedStringTokenizer(value, ","); while (keyValuePairs.hasMoreTokens()) { final String keyValue = keyValuePairs.nextToken(); final QuotedStringTokenizer st = new QuotedStringTokenizer(keyValue, "="); final String keyToken = st.nextToken(); final String arg = st.nextToken(); switch (keyToken) { case "is_undocumented": this.isUndocumented = Boolean.parseBoolean(arg); break; case "name": if (!arg.startsWith("-")) { throw new IllegalArgumentException(arg); } this.name = arg; break; case "short_name": if (!arg.startsWith("-")) { throw new IllegalArgumentException(arg); } this.shortName = arg; break; case "desc": this.description = arg; break; case "params": this.params = arg; break; case "type": this.type = arg.toLowerCase(Locale.ENGLISH); break; case "default": this.defaultValue = arg; break; case "dependency": this.dependency = arg; break; case "conflict": this.conflict = arg; break; case "value_next_arg": this.valueNextArg = Boolean.parseBoolean(arg); break; default: throw new IllegalArgumentException(keyToken); } } // default to boolean if no type is given if (this.type == null) { this.type = "boolean"; } if (this.params == null && "boolean".equals(this.type)) { this.params = "[true|false]"; } } catch (final Exception e) { throw new IllegalArgumentException(origValue); } if (name == null && shortName == null) { throw new IllegalArgumentException(origValue); } }
private void parse(final String origValue) { String value = origValue.trim(); try { value = OptionTemplate.strip(value, '{', '}'); final QuotedStringTokenizer keyValuePairs = new QuotedStringTokenizer(value, ","); while (keyValuePairs.hasMoreTokens()) { final String keyValue = keyValuePairs.nextToken(); final QuotedStringTokenizer st = new QuotedStringTokenizer(keyValue, "="); final String keyToken = st.nextToken(); final String arg = st.nextToken(); switch (keyToken) { case "is_undocumented": this.isUndocumented = Boolean.parseBoolean(arg); break; case "name": if (!arg.startsWith("-")) { throw new IllegalArgumentException(arg); } this.name = arg; break; case "short_name": if (!arg.startsWith("-")) { throw new IllegalArgumentException(arg); } this.shortName = arg; break; case "desc": this.description = arg; break; case "params": this.params = arg; break; case "type": this.type = arg.toLowerCase(Locale.ENGLISH); break; case "default": this.defaultValue = arg; break; case "dependency": this.dependency = arg; break; case "conflict": this.conflict = arg; break; case "value_next_arg": this.valueNextArg = Boolean.parseBoolean(arg); break; case "repeated": this.repeated = true; break; default: throw new IllegalArgumentException(keyToken); } } // default to boolean if no type is given if (this.type == null) { this.type = "boolean"; } if (this.params == null && "boolean".equals(this.type)) { this.params = "[true|false]"; } } catch (final Exception e) { throw new IllegalArgumentException(origValue); } if (name == null && shortName == null) { throw new IllegalArgumentException(origValue); } if (this.repeated && !"string".equals(this.type)) { throw new IllegalArgumentException("repeated option should be of type string: " + this.name); } }