public class CommandLineHelper extends Object
Constructor and Description |
---|
CommandLineHelper() |
Modifier and Type | Method and Description |
---|---|
static List<String> |
cleanAxiomStrings(org.apache.commons.cli.CommandLine line)
Given a command line, get the 'axioms' option(s) and make sure all are properly split and
return one axiom selector per list entry.
|
static Map<String,String> |
getAddPrefixes(org.apache.commons.cli.CommandLine line)
Given a command line, get a map of all prefixes to use and add to the output.
|
static Set<Class<? extends org.semanticweb.owlapi.model.OWLAxiom>> |
getAxiomValues(org.apache.commons.cli.CommandLine line)
Deprecated.
split into methods
cleanAxiomStrings(CommandLine) and others in RelatedObjectsHelper |
static List<String> |
getBaseNamespaces(org.apache.commons.cli.CommandLine line,
IOHelper ioHelper)
Given a command line and an IOHelper, return a list of base namespaces from the '--base-iri'
option.
|
static boolean |
getBooleanValue(org.apache.commons.cli.CommandLine line,
String name,
boolean defaultValue)
Get the boolean value of a command-line option with the given name.
|
static boolean |
getBooleanValue(org.apache.commons.cli.CommandLine line,
String name,
boolean defaultValue,
boolean optionalArg)
Given a command line, an argument name, the boolean default value, and boolean if the arg is
optional, return the value of the command-line option 'name'.
|
static String |
getCommand(org.apache.commons.cli.CommandLine line)
Given a command line, return its first argument, which should be the name of the command to
execute.
|
static org.apache.commons.cli.CommandLine |
getCommandLine(String usage,
org.apache.commons.cli.Options options,
String[] args)
Parse the command line, handle help and other common options, (May exit!) and return a
CommandLine.
|
static org.apache.commons.cli.Options |
getCommonOptions()
Create a new Options object with shared options for 'help' and 'version'.
|
static String |
getDefaultValue(org.apache.commons.cli.CommandLine line,
String name,
String defaultValue)
Get the value of the command-line option with the given name, or return a default value if the
option is not found.
|
static String |
getIndexValue(org.apache.commons.cli.CommandLine line,
int index)
Given a command line and an index, return the argument at that index.
|
static List<org.semanticweb.owlapi.model.OWLOntology> |
getInputOntologies(IOHelper ioHelper,
org.apache.commons.cli.CommandLine line)
Given an IOHelper and a command line, check input options and return a list of loaded input
ontologies.
|
static List<org.semanticweb.owlapi.model.OWLOntology> |
getInputOntologies(IOHelper ioHelper,
org.apache.commons.cli.CommandLine line,
boolean allowEmpty)
Given an IOHelper and a command line, check for required options and return a list of loaded
input ontologies.
|
static List<org.semanticweb.owlapi.model.OWLOntology> |
getInputOntologies(IOHelper ioHelper,
org.apache.commons.cli.CommandLine line,
String catalogPath)
Given an IOHelper, a command line, and the path to a catalog file, check input options and
return a list of loaded input ontologies with the catalog file.
|
static org.semanticweb.owlapi.model.OWLOntology |
getInputOntology(IOHelper ioHelper,
org.apache.commons.cli.CommandLine line)
Given an IOHelper and a command line, check for required options and return a loaded input
ontology.
|
static org.semanticweb.owlapi.model.OWLOntology |
getInputOntology(IOHelper ioHelper,
org.apache.commons.cli.CommandLine line,
String catalogPath)
Given an IOHelper, a command line, and a path to a catalog, return an OWLOntology loaded from
input or input-iri using the specified catalog (or null).
|
static IOHelper |
getIOHelper(org.apache.commons.cli.CommandLine line)
Given a command line, return an initialized IOHelper.
|
static String |
getOptionalValue(org.apache.commons.cli.CommandLine line,
String name)
Get the value of the command-line option with the given name.
|
static List<String> |
getOptionalValues(org.apache.commons.cli.CommandLine line,
String name)
Get the value of the command-line options with the given name.
|
static List<String> |
getOptionValues(org.apache.commons.cli.CommandLine line,
String name)
Given a command line, return the values for an option as a list.
|
static File |
getOutputFile(org.apache.commons.cli.CommandLine line)
Given a command line, check for the required options and return a File for saving data.
|
static org.semanticweb.owlapi.model.IRI |
getOutputIRI(org.apache.commons.cli.CommandLine line)
Given a command line, check for the required options and return an IRI to be used as the
OntologyIRI for the output ontology.
|
static org.semanticweb.owlapi.reasoner.OWLReasonerFactory |
getReasonerFactory(org.apache.commons.cli.CommandLine line)
Given a string of a reasoner name from user input, return the reasoner factory.
|
static org.semanticweb.owlapi.reasoner.OWLReasonerFactory |
getReasonerFactory(org.apache.commons.cli.CommandLine line,
boolean allowEMR)
Given a string of a reasoner name from user input, return the reasoner factory.
|
static String |
getRequiredValue(org.apache.commons.cli.CommandLine line,
String name,
String message)
Get the value of the command-line option with the given name, or throw an
IllegalArgumentException with a given message if the option is not found.
|
static Set<org.semanticweb.owlapi.model.IRI> |
getTerms(IOHelper ioHelper,
org.apache.commons.cli.CommandLine line)
Given an IOHelper and a command line, check for the required options and return a set of IRIs
for terms.
|
static Set<org.semanticweb.owlapi.model.IRI> |
getTerms(IOHelper ioHelper,
org.apache.commons.cli.CommandLine line,
boolean allowEmpty)
As getTerms, but allow the list to be empty.
|
static Set<org.semanticweb.owlapi.model.IRI> |
getTerms(IOHelper ioHelper,
org.apache.commons.cli.CommandLine line,
String singles,
String paths)
Given an IOHelper and a command line, and the names of two options, check for the required
options and return a set of IRIs for terms.
|
static void |
handleException(Exception exception)
Shared method for dealing with exceptions, printing help, and exiting.
|
static void |
handleException(String usage,
org.apache.commons.cli.Options options,
Exception exception)
Shared method for dealing with exceptions, printing help, and exiting.
|
static boolean |
hasFlagOrCommand(org.apache.commons.cli.CommandLine line,
String name)
Return true if a command line include the option with the given name, or the command with the
given name.
|
static org.semanticweb.owlapi.model.IRI |
maybeCreateIRI(IOHelper ioHelper,
String term,
String field)
Try to create an IRI from a string input.
|
static org.apache.commons.cli.CommandLine |
maybeGetCommandLine(String usage,
org.apache.commons.cli.Options options,
String[] args,
boolean stopAtNonOption)
Parse the command line, handle help and other common options, and return null or a CommandLine.
|
static void |
maybeSaveOutput(org.apache.commons.cli.CommandLine line,
org.semanticweb.owlapi.model.OWLOntology ontology)
Given a command line and an ontology, for each `--output` option (if any), save a copy of the
ontology to the specified path.
|
static List<String> |
parseArgList(String toProcess)
Given a single string, return a list of strings split at whitespace but allowing for quoted
values, as a command-line parser does.
|
static String[] |
parseArgs(String toProcess)
Given a single string, return an array of strings split at whitespace but allowing for quoted
values, as a command-line parser does.
|
static void |
printHelp(String usage,
org.apache.commons.cli.Options options)
Print a help message for a command.
|
static void |
printVersion()
Print the ROBOT version
|
protected static List<String> |
splitSelects(String selects)
Given an input string, return a list of the string split on whitespace, while ignoring any
whitespace in single string quotes.
|
static CommandState |
updateInputOntology(IOHelper ioHelper,
CommandState state,
org.apache.commons.cli.CommandLine line)
Given an IOHelper, a state object, and a command line, update the state with the ontology.
|
static CommandState |
updateInputOntology(IOHelper ioHelper,
CommandState state,
org.apache.commons.cli.CommandLine line,
boolean required)
Given an IOHelper, a state object, a command line, and a "required" flag, update the state with
the ontology.
|
public static List<String> parseArgList(String toProcess) throws Exception
toProcess
- the string to parseException
- on parsing problemspublic static String[] parseArgs(String toProcess) throws Exception
toProcess
- the string to parseException
- on parsing problemspublic static List<String> getOptionValues(org.apache.commons.cli.CommandLine line, String name)
line
- the command line to usename
- the name of the option to findpublic static String getIndexValue(org.apache.commons.cli.CommandLine line, int index)
line
- the command line to useindex
- the index of the argumentpublic static String getCommand(org.apache.commons.cli.CommandLine line)
line
- the command line to usepublic static boolean hasFlagOrCommand(org.apache.commons.cli.CommandLine line, String name)
line
- the command line to usename
- the name of the flag or argument to check forpublic static List<String> cleanAxiomStrings(org.apache.commons.cli.CommandLine line)
line
- the command line to usepublic static List<String> getBaseNamespaces(org.apache.commons.cli.CommandLine line, IOHelper ioHelper)
line
- the command line to useioHelper
- the IOHelper to resolve prefixespublic static boolean getBooleanValue(org.apache.commons.cli.CommandLine line, String name, boolean defaultValue, boolean optionalArg)
line
- the command line to usename
- the name of the option to finddefaultValue
- the default value to use if the option is not providedoptionalArg
- if true, the option without an arg will return true@Deprecated public static Set<Class<? extends org.semanticweb.owlapi.model.OWLAxiom>> getAxiomValues(org.apache.commons.cli.CommandLine line)
cleanAxiomStrings(CommandLine)
and others in RelatedObjectsHelper
line
- the command line to usepublic static boolean getBooleanValue(org.apache.commons.cli.CommandLine line, String name, boolean defaultValue)
line
- the command line to usename
- the name of the option to finddefaultValue
- the default value to usepublic static String getOptionalValue(org.apache.commons.cli.CommandLine line, String name)
line
- the command line to usename
- the name of the option to findpublic static List<String> getOptionalValues(org.apache.commons.cli.CommandLine line, String name)
line
- the command line to usename
- the name of the option to findpublic static String getDefaultValue(org.apache.commons.cli.CommandLine line, String name, String defaultValue)
line
- the command line to usename
- the name of the option to finddefaultValue
- the default value to usepublic static String getRequiredValue(org.apache.commons.cli.CommandLine line, String name, String message) throws IllegalArgumentException
line
- the command line to usename
- the name of the option to findmessage
- the message for the exceptionIllegalArgumentException
- if the option is not foundpublic static IOHelper getIOHelper(org.apache.commons.cli.CommandLine line) throws IOException
line
- the command line to useIOException
- on issue creating IOHelper with given contextpublic static org.semanticweb.owlapi.model.OWLOntology getInputOntology(IOHelper ioHelper, org.apache.commons.cli.CommandLine line) throws IllegalArgumentException, IOException
ioHelper
- the IOHelper to load the ontology withline
- the command line to useIllegalArgumentException
- if requires options are missingIOException
- if the ontology cannot be loadedpublic static org.semanticweb.owlapi.model.OWLOntology getInputOntology(IOHelper ioHelper, org.apache.commons.cli.CommandLine line, String catalogPath) throws IllegalArgumentException, IOException
ioHelper
- the IOHelper to load the ontology withline
- the command line to usecatalogPath
- the catalog to use to load importsIllegalArgumentException
- if requires options are missingIOException
- if the ontology cannot be loadedpublic static List<org.semanticweb.owlapi.model.OWLOntology> getInputOntologies(IOHelper ioHelper, org.apache.commons.cli.CommandLine line, boolean allowEmpty) throws IllegalArgumentException, IOException
ioHelper
- the IOHelper to load the ontology withline
- the command line to useallowEmpty
- if an empty list may be returned (when chaining commands, an input was
already provided)IllegalArgumentException
- if requires options are missingIOException
- if the ontology cannot be loadedpublic static CommandState updateInputOntology(IOHelper ioHelper, CommandState state, org.apache.commons.cli.CommandLine line) throws IllegalArgumentException
ioHelper
- the IOHelper to load the ontology withstate
- the input state, maybe nullline
- the command line to useIllegalArgumentException
- if requires options are missingpublic static CommandState updateInputOntology(IOHelper ioHelper, CommandState state, org.apache.commons.cli.CommandLine line, boolean required) throws IllegalArgumentException
ioHelper
- the IOHelper to load the ontology withstate
- the input state, maybe nullline
- the command line to userequired
- when true, throw an exception if ontology is not foundIllegalArgumentException
- if requires options are missingpublic static File getOutputFile(org.apache.commons.cli.CommandLine line) throws IllegalArgumentException
line
- the command line to useIllegalArgumentException
- if required options are not foundpublic static org.semanticweb.owlapi.model.IRI getOutputIRI(org.apache.commons.cli.CommandLine line)
line
- the command line to usepublic static void maybeSaveOutput(org.apache.commons.cli.CommandLine line, org.semanticweb.owlapi.model.OWLOntology ontology) throws IOException
line
- the command lien to useontology
- the ontology to saveIOException
- on any problempublic static org.semanticweb.owlapi.model.IRI maybeCreateIRI(IOHelper ioHelper, String term, String field)
ioHelper
- IOHelper to useterm
- the term to convert to an IRIfield
- the field in which the term was entered, for reportingpublic static Map<String,String> getAddPrefixes(org.apache.commons.cli.CommandLine line) throws IOException
line
- the command line to useIOException
- if the prefixes are not formatted correctly or a JSON file cannot be readpublic static Set<org.semanticweb.owlapi.model.IRI> getTerms(IOHelper ioHelper, org.apache.commons.cli.CommandLine line) throws IllegalArgumentException, IOException
ioHelper
- the IOHelper to use for loading the termsline
- the command line to useIllegalArgumentException
- if the required options are not foundIOException
- if the term file cannot be loadedpublic static Set<org.semanticweb.owlapi.model.IRI> getTerms(IOHelper ioHelper, org.apache.commons.cli.CommandLine line, boolean allowEmpty) throws IllegalArgumentException, IOException
ioHelper
- the IOHelper to use for loading the termsline
- the command line to useallowEmpty
- true if empty lists of properties are allowedIllegalArgumentException
- if the required options are not foundIOException
- if the term file cannot be loadedpublic static Set<org.semanticweb.owlapi.model.IRI> getTerms(IOHelper ioHelper, org.apache.commons.cli.CommandLine line, String singles, String paths) throws IllegalArgumentException, IOException
ioHelper
- the IOHelper to use for loading the termsline
- the command line to usesingles
- the option name for single terms, or nullpaths
- the option name for term file paths, or nullIllegalArgumentException
- if the required options are not foundIOException
- if the term file cannot be loadedpublic static org.semanticweb.owlapi.reasoner.OWLReasonerFactory getReasonerFactory(org.apache.commons.cli.CommandLine line)
line
- the command line to usepublic static org.semanticweb.owlapi.reasoner.OWLReasonerFactory getReasonerFactory(org.apache.commons.cli.CommandLine line, boolean allowEMR)
line
- the command line to useallowEMR
- boolean specifying if EMR can be returnedpublic static void printHelp(String usage, org.apache.commons.cli.Options options)
usage
- the usage information for the commandoptions
- the command line options for the commandpublic static void printVersion() throws IOException
IOException
- on issue getting info from JARpublic static org.apache.commons.cli.Options getCommonOptions()
public static org.apache.commons.cli.CommandLine maybeGetCommandLine(String usage, org.apache.commons.cli.Options options, String[] args, boolean stopAtNonOption) throws org.apache.commons.cli.ParseException, IOException
usage
- the usage string for this commandoptions
- the command-line options for this commandargs
- the command-line arguments providedstopAtNonOption
- same as CommandLineParserorg.apache.commons.cli.ParseException
- if the arguments cannot be parsedIOException
- on issue printing versionpublic static org.apache.commons.cli.CommandLine getCommandLine(String usage, org.apache.commons.cli.Options options, String[] args) throws org.apache.commons.cli.ParseException, IOException
usage
- the usage string for this commandoptions
- the command-line options for this commandargs
- the command-line arguments providedorg.apache.commons.cli.ParseException
- if the arguments cannot be parsedIOException
- on issue printing versionpublic static void handleException(Exception exception)
exception
- the exception to handlepublic static void handleException(String usage, org.apache.commons.cli.Options options, Exception exception)
usage
- the usage string for this command; WARN: not usedoptions
- the command-line options for this command; WARN: not usedexception
- the exception to handleprotected static List<String> splitSelects(String selects)
selects
- String of select options to splitpublic static List<org.semanticweb.owlapi.model.OWLOntology> getInputOntologies(IOHelper ioHelper, org.apache.commons.cli.CommandLine line) throws IllegalArgumentException, IOException
ioHelper
- the IOHelper to load the ontology withline
- the command line to useIllegalArgumentException
- on bad patternIOException
- if the ontology cannot be loadedpublic static List<org.semanticweb.owlapi.model.OWLOntology> getInputOntologies(IOHelper ioHelper, org.apache.commons.cli.CommandLine line, String catalogPath) throws IOException
ioHelper
- the IOHelper to load the ontology withline
- the command line to usecatalogPath
- the catalog file to useIOException
- if the ontology cannot be loadedCopyright © 2015–2020. All rights reserved.