Registers an option in this argument parser. @param name The name of the option to recognize (e.g. --foo). @param meta The meta-variable to associate with the value of the option. @param help A short description of this option. @throws IllegalArgumentException if the given name was already u
(final String name,
final String meta,
final String help)
| 72 | * @throws IllegalArgumentException if any of the given strings is empty. |
| 73 | */ |
| 74 | public void addOption(final String name, |
| 75 | final String meta, |
| 76 | final String help) { |
| 77 | if (name.isEmpty()) { |
| 78 | throw new IllegalArgumentException("empty name"); |
| 79 | } else if (name.charAt(0) != '-') { |
| 80 | throw new IllegalArgumentException("name must start with a `-': " + name); |
| 81 | } else if (meta != null && meta.isEmpty()) { |
| 82 | throw new IllegalArgumentException("empty meta"); |
| 83 | } else if (help.isEmpty()) { |
| 84 | throw new IllegalArgumentException("empty help"); |
| 85 | } |
| 86 | final String[] prev = options.put(name, new String[] { meta, help }); |
| 87 | if (prev != null) { |
| 88 | options.put(name, prev); // Undo the `put' above. |
| 89 | throw new IllegalArgumentException("Option " + name + " already defined" |
| 90 | + " in " + this); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Registers an option that doesn't take a value in this argument parser. |
no test coverage detected