| 252 | } |
| 253 | |
| 254 | @SuppressWarnings("checkstyle:AbbreviationAsWordInName") |
| 255 | public static class CLIBuilder { |
| 256 | private final ArrayList<Opt> opts = new ArrayList<>(); |
| 257 | private final ArrayList<Arg> args = new ArrayList<>(); |
| 258 | private final ArrayList<Arg> optionalArgs = new ArrayList<>(); |
| 259 | |
| 260 | /** |
| 261 | * Add an option to be parsed. |
| 262 | * @param shortName the short single character name of the option (no `-` character proceeds it). |
| 263 | * @param longName the multi character name of the option (no `--` characters proceed it). |
| 264 | * @param defaultValue the value that will be returned of the command if none is given. null if none is given. |
| 265 | * @return a builder to be used to continue creating the command line. |
| 266 | */ |
| 267 | public CLIBuilder opt(String shortName, String longName, Object defaultValue) { |
| 268 | return opt(shortName, longName, defaultValue, null, null); |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * Add an option to be parsed. |
| 273 | * @param shortName the short single character name of the option (no `-` character proceeds it). |
| 274 | * @param longName the multi character name of the option (no `--` characters proceed it). |
| 275 | * @param defaultValue the value that will be returned of the command if none is given. null if none is given. |
| 276 | * @param parse an optional function to transform the string to something else. If null a NOOP is used. |
| 277 | * @return a builder to be used to continue creating the command line. |
| 278 | */ |
| 279 | public CLIBuilder opt(String shortName, String longName, Object defaultValue, Parse parse) { |
| 280 | return opt(shortName, longName, defaultValue, parse, null); |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * Add an option to be parsed. |
| 285 | * @param shortName the short single character name of the option (no `-` character proceeds it). |
| 286 | * @param longName the multi character name of the option (no `--` characters proceed it). |
| 287 | * @param defaultValue the value that will be returned of the command if none is given. null if none is given. |
| 288 | * @param parse an optional function to transform the string to something else. If null a NOOP is used. |
| 289 | * @param assoc an association command to decide what to do if the option appears multiple times. If null LAST_WINS is used. |
| 290 | * @return a builder to be used to continue creating the command line. |
| 291 | */ |
| 292 | public CLIBuilder opt(String shortName, String longName, Object defaultValue, Parse parse, Assoc assoc) { |
| 293 | opts.add(new Opt(shortName, longName, defaultValue, parse, assoc, false)); |
| 294 | return this; |
| 295 | } |
| 296 | |
| 297 | /** |
| 298 | * Add a boolean option that enables something. |
| 299 | * @param shortName the short single character name of the option (no `-` character proceeds it). |
| 300 | * @param longName the multi character name of the option (no `--` characters proceed it). |
| 301 | * @return a builder to be used to continue creating the command line. |
| 302 | */ |
| 303 | public CLIBuilder boolOpt(String shortName, String longName) { |
| 304 | opts.add(new Opt(shortName, longName, false, null, null, true)); |
| 305 | return this; |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * Add a named argument. |
| 310 | * @param name the name of the argument. |
| 311 | * @return a builder to be used to continue creating the command line. |
nothing calls this directly
no outgoing calls
no test coverage detected