Java源码示例:com.sampullara.cli.Args
示例1
public <T> T parse(String[] args, T inputArgs, Function<? super T, String> validationFunction) {
try {
List<String> extraArgs = Args.parse(inputArgs, args);
if (extraArgs.size() > 0) {
printUsageAndExit(inputArgs, "Passed in unnecessary args: " + StringUtils.join(extraArgs, "; "));
}
String validationMessage = validationFunction.valueOf(inputArgs);
if (validationMessage != null) {
printUsageAndExit(inputArgs, validationMessage);
}
} catch (IllegalArgumentException exc) {
printUsageAndExit(inputArgs, ExceptionUtils.getStackTrace(exc));
}
LOG.info("Arguments parsed: " + inputArgs.toString());
return inputArgs;
}
示例2
public static void main( String[] args )
throws Exception
{
Commands command = new Commands();
try
{
Args.parse( command, args );
}
catch ( IllegalArgumentException e )
{
LOGGER.error( e.getMessage(), e );
Args.usage( command );
return;
}
ArchivaCli cli = new ArchivaCli();
try
{
cli.execute( command );
}
finally
{
cli.destroy();
}
}
示例3
/**
* @param args
* @throws InterruptedException
* @throws FileNotFoundException
*/
public static void main(String[] args) throws InterruptedException, FileNotFoundException {
FailFast failFast = new FailFast(Thread.currentThread());
{ // Fail Fast thread
Thread fail_fast_thread = new Thread(failFast);
fail_fast_thread.setName("fail_fast_thread");
fail_fast_thread.start();
}
try
{
Args.parse(ItemAttributesImporter.class, args);
{ // Determine opMode by checking for urlFile
if (urlFile !=null) {
opMode = OperationMode.OPERATION_MODE_FILE_IMPORTER;
}
}
DefaultApiClient client = new DefaultApiClient(apiUrl,consumerKey,consumerSecret,API_TIMEOUT);
ItemAttributesImporter fixer = new ItemAttributesImporter(client);
fixer.setFailFast(failFast);
fixer.run();
}
catch (IllegalArgumentException e)
{
e.printStackTrace();
Args.usage(ItemAttributesImporter.class);
}
}
示例4
/**
* @param args
* @throws InterruptedException
* @throws FileNotFoundException
*/
public static void main(String[] args) throws InterruptedException, FileNotFoundException {
FailFast failFast = new FailFast(Thread.currentThread());
{ // Fail Fast thread
Thread fail_fast_thread = new Thread(failFast);
fail_fast_thread.setName("fail_fast_thread");
fail_fast_thread.start();
}
try
{
Args.parse(FileItemAttributesImporter.class, args);
DefaultApiClient client = new DefaultApiClient(apiUrl,consumerKey,consumerSecret,API_TIMEOUT);
FileItemAttributesImporter fixer = new FileItemAttributesImporter(client);
fixer.setFailFast(failFast);
fixer.run();
}
catch (IllegalArgumentException e)
{
e.printStackTrace();
Args.usage(FileItemAttributesImporter.class);
}
}
示例5
/**
* @param args
* , three arguments, whether all the words are combined or separated
* @throws IOException
* @throws OutOfVocabularyException
*/
public static void main(String[] args) throws VectorsException, IOException {
// arguments
try {
Args.parse(ExpandQuery.class, args);
} catch (IllegalArgumentException e) {
Args.usage(ExpandQuery.class);
System.exit(1);
}
QueryExpander queryExpander = new QueryExpander(new Vectors(new FileInputStream(new File(vectorsFileName))),
combineTerms, QueryExpander.TermSelection.valueOf(termSelectionString));
// read queries, one per line
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(inputFileName), "UTF-8"));
String line = br.readLine();
line = br.readLine();
while (line != null) {
// qid and query
String[] parts = line.split(",");
String qid = parts[0];
String query = parts[1];
List<Distance.ScoredTerm> expansion = queryExpander.expand(query);
PrintWriter pw = new PrintWriter(new FileWriter(new File(outputFolderName, qid + ".terms")));
for (Distance.ScoredTerm scoredTerm : expansion)
pw.println(scoredTerm.getTerm() + "\t" + scoredTerm.getScore());
pw.close();
line = br.readLine();
}
br.close();
}
示例6
private void execute( Commands command )
throws Exception
{
if ( command.help )
{
Args.usage( command );
}
else if ( command.version )
{
LOGGER.info( "Version: {}", getVersion() );
}
else if ( command.convert )
{
LOGGER.error( "Conversion is not available anymore" );
}
else if ( command.scan )
{
if ( command.repository == null )
{
LOGGER.error( "The repository must be specified." );
Args.usage( command );
return;
}
doScan( command.repository, command.consumers.split( "," ) );
}
else if ( command.listConsumers )
{
dumpAvailableConsumers();
}
else
{
Args.usage( command );
}
}
示例7
private static <T> void printUsageAndExit(T inputArgs, String message) {
Args.usage(inputArgs);
System.err.println(message);
System.exit(-1);
}