public class CliSpecification extends Object
| Modifier and Type | Method and Description |
|---|---|
CliSpecification |
addValidation(java.util.function.Predicate<Cli> validationRule,
java.util.function.Function<Cli,String> errorMessageFunction)
Add an additional validation rule to this overall specification.
|
CliSpecification |
addValidation(java.util.function.Predicate<Cli> validationRule,
String errorMessage)
Add an additional validation rule to this overall specification.
|
static CliSpecification |
create(CliOptionBuilder... options)
Create a new
CliSpecification with the given options. |
static CliSpecification |
createWithHelp(CliOptionBuilder... options)
Create a new
CliSpecification with a default help option
with the option name "-h" and long name "--help" along with the given other options. |
CliSpecification |
description(String description)
Sets a description to this usage to describe what this program
does.
|
String |
generateUsage()
Generate the Usage String of this specification.
|
static CliOptionBuilder |
group(CliOptionBuilder... options)
Create a new group of options where the specification is
only valid if either all the required options in the group are present,
or none of them are present.
|
boolean |
helpRequested(String[] args)
Is one of these passed in arguments -h, --h, -help or --help.
|
static BasicCliOptionBuilder |
option(String optName)
Create a new
BasicCliOptionBuilder that
is mapped to the given option name. |
Cli |
parse(String[] args)
Parse the command line options of the given String array, often the arguments from a Main method.
|
Cli |
parse(URL url)
Parse the query parameters as a urlencoded command line arguments.
|
CliSpecification |
programName(String programName)
Sets this program name to this usage.
|
static CliOptionBuilder |
radio(CliOptionBuilder... radioOptions)
Create a new Radio group of options where the specification
is only valid if only one of the given options
can be selected.
|
public static CliSpecification createWithHelp(CliOptionBuilder... options)
CliSpecification with a default help option
with the option name "-h" and long name "--help" along with the given other options.options - varargs of other options to include in this specification;
may be empty but no item in the list can be null.CliSpecification will never be null.public static CliSpecification create(CliOptionBuilder... options)
CliSpecification with the given options.options - varargs of options to include in this specification;
may be empty but no item in the list can be null.CliSpecification will never be null.public static BasicCliOptionBuilder option(String optName)
BasicCliOptionBuilder that
is mapped to the given option name. By default this radio group is not required,
to make it required in the specification set the CliOptionBuilder.setRequired(boolean)
method.optName - the name of the option that will be
in the specification as "-$optName".BasicCliOptionBuilder will never be null.public static CliOptionBuilder radio(CliOptionBuilder... radioOptions)
CliOptionBuilder.setRequired(boolean)
method.radioOptions - a varargs list of radio options;
none of the options may be null.CliOptionBuilder.public static CliOptionBuilder group(CliOptionBuilder... options)
CliOptionBuilder.setRequired(boolean)
method.options - a varargs list of options in this group;
none of the options may be null.CliOptionBuilder.public CliSpecification addValidation(java.util.function.Predicate<Cli> validationRule, String errorMessage)
validationRule - A Predicate function that passes in the
parsed Cli instance from a program invocation
that will return true if this Cli passes this new validation
rule; false otherwise. This Predicate can not be null.errorMessage - The message to use in the new CliValidationException
that will be thrown if the given predicate returns false.NullPointerException - if validationRule is null.public CliSpecification addValidation(java.util.function.Predicate<Cli> validationRule, java.util.function.Function<Cli,String> errorMessageFunction)
validationRule - A Predicate function that passes in the
parsed Cli instance from a program invocation
that will return true if this Cli passes this new validation
rule; false otherwise. This Predicate can not be null.errorMessageFunction - A function to generate the message to use in the new CliValidationException
that will be thrown if the given predicate returns false.NullPointerException - if either parameter is null.public CliSpecification description(String description)
description - the description of this program,
if null, then there is no description.public CliSpecification programName(String programName)
programName - the name of this program,
if null, then there is no name.public Cli parse(URL url) throws IOException
key=value means -key value.url - the URL to parse; can not e null.Cli of the parsed options in the URL parameters.IOException - if there is a prolem decodeing the URL parametersCliValidationException - if the url parameters violate this CliSpecification.public String generateUsage()
public boolean helpRequested(String[] args)
args - the command line arguments to parse.true if at least one of these arguments
is "-h", "--h", "-help" or "--help"; false otherwisepublic Cli parse(String[] args) throws CliValidationException
args - the arguments array to parse.Cli of the parsed options.CliValidationException - if the arguments violate this CliSpecification.Copyright © 2019 NIH/NCATS. All rights reserved.