當前位置: 首頁>>代碼示例>>Java>>正文


Java ArgumentParsers類代碼示例

本文整理匯總了Java中net.sourceforge.argparse4j.ArgumentParsers的典型用法代碼示例。如果您正苦於以下問題:Java ArgumentParsers類的具體用法?Java ArgumentParsers怎麽用?Java ArgumentParsers使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ArgumentParsers類屬於net.sourceforge.argparse4j包,在下文中一共展示了ArgumentParsers類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: loadFromCLI

import net.sourceforge.argparse4j.ArgumentParsers; //導入依賴的package包/類
/**
 * Reads a configuration file from the passed CLI args
 *
 * @return Path to config file, or exception
 * @throws ConfigParseException if arguments were incorrectly specified, or nothing was passed (in which case it will print "usage" details)
 */
public static String loadFromCLI(String programName, String... args) throws ConfigParseException {
    ArgumentParser parser = ArgumentParsers.newArgumentParser("java -jar " + programName + "-[VERSION].jar").defaultHelp(true);
    parser.addArgument("--config").metavar("/path/to/app-config.json").required(true).help("Path to configuration file");

    try {
        // parse CLI args and return config file
        Namespace cli = parser.parseArgs(args);
        return cli.getString("config");

    } catch (ArgumentParserException e) {
        // show help message and stop execution
        parser.handleError(e);
        throw new ConfigParseException(e);
    }
}
 
開發者ID:salesforce,項目名稱:pyplyn,代碼行數:22,代碼來源:AppConfigFileLoader.java

示例2: getArgumentParser

import net.sourceforge.argparse4j.ArgumentParsers; //導入依賴的package包/類
static ArgumentParser getArgumentParser() {
    ArgumentParser parser = ArgumentParsers.newArgumentParser("dockerfile-image-update", true)
            .description("Image Updates through Pull Request Automator");

    parser.addArgument("-o", "--org")
            .help("search within specific organization (default: all of github)");
    /* Currently, because of argument passing reasons, you can only specify one branch. */
    parser.addArgument("-b", "--branch")
            .help("make pull requests for given branch name (default: master)");
    parser.addArgument("-g", "--" + Constants.GIT_API)
            .help("link to github api; overrides environment variable");
    parser.addArgument("-f", "--auto-merge").action(Arguments.storeTrue())
            .help("NOT IMPLEMENTED / set to automatically merge pull requests if available");
    parser.addArgument("-m")
            .help("message to provide for pull requests");
    parser.addArgument("-c")
            .help("additional commit message for the commits in pull requests");
    return parser;
}
 
開發者ID:salesforce,項目名稱:dockerfile-image-update,代碼行數:20,代碼來源:CommandLine.java

示例3: doMain

import net.sourceforge.argparse4j.ArgumentParsers; //導入依賴的package包/類
protected void doMain(String args[]) {
    ArgumentParser parser = ArgumentParsers.newArgumentParser(getClass().getSimpleName());

    parser.addArgument("--out")
            .dest("out")
            .metavar("FILE")
            .nargs("?")
            .setDefault("stdout")
            .help("Writes the script to the output file; default is stdout");

    addArguments(parser);

    Namespace namespace = parser.parseArgsOrFail(args);
    String file = namespace.getString("out");

    try (PrintStream out = file.equals("stdout") ? System.out : new PrintStream(new FileOutputStream(file))) {
        generateScript(namespace, out);
    } catch (IOException e) {
        System.err.println("Script generation failed");
        e.printStackTrace(System.err);
    }
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:23,代碼來源:HiveScriptGenerator.java

示例4: main

import net.sourceforge.argparse4j.ArgumentParsers; //導入依賴的package包/類
public static void main(String[] args) {
    ArgumentParser parser = ArgumentParsers.newArgumentParser("AngusMe");
    parser.description("Angus SDK configurator");

    parser.addArgument("-s", "--show").action(Arguments.storeTrue())
            .help("display current configuration if exists");

    parser.addArgument("-d", "--delete").action(Arguments.storeTrue())
            .help("remove current configuration if exists");

    try {
        Namespace res = parser.parseArgs(args);
        if (res.getBoolean("show")) {
            show();
        } else if (res.getBoolean("delete")) {
            delete();
        } else {
            update();
        }
    } catch (ArgumentParserException e) {
        parser.handleError(e);
    }
}
 
開發者ID:angus-ai,項目名稱:angus-sdk-java,代碼行數:24,代碼來源:AngusMe.java

示例5: main

import net.sourceforge.argparse4j.ArgumentParsers; //導入依賴的package包/類
public static void main(String... args) {
  WSFRealtimeMain m = new WSFRealtimeMain();

  ArgumentParser parser = ArgumentParsers.newArgumentParser("wsf-gtfsrealtime");
  parser.description("Produces a GTFS-realtime feed from the Washington State Ferries API");
  parser.addArgument("--" + ARG_CONFIG_FILE).type(File.class).help("configuration file path");
  Namespace parsedArgs;

  try {
    parsedArgs = parser.parseArgs(args);
    File configFile = parsedArgs.get(ARG_CONFIG_FILE);
    m.run(configFile);
  } catch (CreationException | ConfigurationException | ProvisionException e) {
    _log.error("Error in startup:", e);
    System.exit(-1);
  } catch (ArgumentParserException ex) {
    parser.handleError(ex);
  }
}
 
開發者ID:kurtraschke,項目名稱:wsf-gtfsrealtime,代碼行數:20,代碼來源:WSFRealtimeMain.java

示例6: main

import net.sourceforge.argparse4j.ArgumentParsers; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    
	ArgumentParser parser = ArgumentParsers.newArgumentParser("ImpressionsToInfluxDb")
            .defaultHelp(true)
            .description("Read Seldon impressions and send stats to influx db");
	parser.addArgument("-t", "--topic").setDefault("impressions").help("Kafka topic to read from");
	parser.addArgument("-k", "--kafka").setDefault("localhost:9092").help("Kafka server and port");
	parser.addArgument("-z", "--zookeeper").setDefault("localhost:2181").help("Zookeeper server and port");
	parser.addArgument("-i", "--influxdb").setDefault("localhost:8086").help("Influxdb server and port");
	parser.addArgument("-u", "--influx-user").setDefault("root").help("Influxdb user");
	parser.addArgument("-p", "--influx-password").setDefault("root").help("Influxdb password");
	parser.addArgument("-d", "--influx-database").setDefault("seldon").help("Influxdb database");
	parser.addArgument("--influx-measurement-impressions").setDefault("impressions").help("Influxdb impressions measurement");
	parser.addArgument("--influx-measurement-requests").setDefault("requests").help("Influxdb requests measurement");
    
    Namespace ns = null;
    try {
        ns = parser.parseArgs(args);
        ImpressionsToInfluxDb.process(ns);
    } catch (ArgumentParserException e) {
        parser.handleError(e);
        System.exit(1);
    }
}
 
開發者ID:SeldonIO,項目名稱:seldon-server,代碼行數:25,代碼來源:ImpressionsToInfluxDb.java

示例7: main

import net.sourceforge.argparse4j.ArgumentParsers; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    
	ArgumentParser parser = ArgumentParsers.newArgumentParser("PredictionsToInfluxDb")
            .defaultHelp(true)
            .description("Read Seldon predictions and send stats to influx db");
	parser.addArgument("-t", "--topic").setDefault("Predictions").help("Kafka topic to read from");
	parser.addArgument("-k", "--kafka").setDefault("localhost:9092").help("Kafka server and port");
	parser.addArgument("-z", "--zookeeper").setDefault("localhost:2181").help("Zookeeper server and port");
	parser.addArgument("-i", "--influxdb").setDefault("localhost:8086").help("Influxdb server and port");
	parser.addArgument("-u", "--influx-user").setDefault("root").help("Influxdb user");
	parser.addArgument("-p", "--influx-password").setDefault("root").help("Influxdb password");
	parser.addArgument("-d", "--influx-database").setDefault("seldon").help("Influxdb database");
	parser.addArgument("--influx-measurement").setDefault("predictions").help("Influxdb Predictions measurement");
    
    Namespace ns = null;
    try {
        ns = parser.parseArgs(args);
        PredictionsToInfluxDb.process(ns);
    } catch (ArgumentParserException e) {
        parser.handleError(e);
        System.exit(1);
    }
}
 
開發者ID:SeldonIO,項目名稱:seldon-server,代碼行數:24,代碼來源:PredictionsToInfluxDb.java

示例8: main

import net.sourceforge.argparse4j.ArgumentParsers; //導入依賴的package包/類
public static void main(String[] args) {
    ArgumentParser parser = ArgumentParsers.newArgumentParser("AdlChecker")
            .defaultHelp(true)
            .description("Checks the syntax of ADL files");

    parser.addArgument("file").nargs("*")
            .help("File to calculate checksum");

    Namespace ns = null;
    try {
        ns = parser.parseArgs(args);
    } catch (ArgumentParserException e) {
        parser.handleError(e);
        System.exit(1);
    }

    if(ns.getList("file").isEmpty()) {
        parser.printUsage();
        parser.printHelp();
    }

    validateArchetypes(ns.getList("file"));
}
 
開發者ID:nedap,項目名稱:archie,代碼行數:24,代碼來源:AdlChecker.java

示例9: handleArguments

import net.sourceforge.argparse4j.ArgumentParsers; //導入依賴的package包/類
public Option handleArguments(String argv[]) {
    ArgumentParser parser = ArgumentParsers.newArgumentParser("Detector")
            .defaultHelp(true)
            .description("Convert Zawgyi <-> Unicode encodings.");

    parser.addArgument("-t", "--to")
            .choices("zawgyi", "unicode")
            .required(true)
            .help("Specify hash function to use");

    parser.addArgument("files").nargs("*")
            .help("Files to convert");

    try {
        parser.parseArgs(argv, this);
    } catch (ArgumentParserException e) {
        parser.handleError(e);
        System.exit(1);
    }

    return this;
}
 
開發者ID:htooaunghlaing,項目名稱:NyaungUConverter,代碼行數:23,代碼來源:PaytanConverter.java

示例10: parseArgs

import net.sourceforge.argparse4j.ArgumentParsers; //導入依賴的package包/類
private static Namespace parseArgs(String[] args) {
	ArgumentParser parser =
	        ArgumentParsers.newArgumentParser("moco", false).description("The Monty compiler.").epilog(
	                "Without -S or -c the program is compiled and directly executed.");

	parser.addArgument("--help").action(Arguments.help()).help("Print this help and exit.");
	parser.addArgument("-S", "--emit-assembly").action(Arguments.storeTrue()).dest("emitAssembly").help(
	        "Emit the LLVM assembly and stop.");
	parser.addArgument("-c", "--compile-only").action(Arguments.storeTrue()).dest("compileOnly").help(
	        "Only compile the executable without running it.");
	parser.addArgument("-e", "--stop-on-first-error").action(Arguments.storeTrue()).dest("stopOnFirstError").help(
	        "Stop the compilation on the first encountered error.");
	parser.addArgument("-p", "--print-ast").action(Arguments.storeTrue()).dest("printAST").help("Print the AST.");
	parser.addArgument("-d", "--debug-parsetree").action(Arguments.storeTrue()).dest("debugParseTree").help(
	        "Debug the parsetree without running anything.");
	parser.addArgument("-o").metavar("<file>").dest("outputFile").help("Write output to <file>.");
	parser.addArgument("file").nargs("?").help("Monty file to run.");

	Namespace ns = null;
	try {
		ns = parser.parseArgs(args);
	} catch (ArgumentParserException ape) {
		parser.handleError(ape);
	}
	return ns;
}
 
開發者ID:MontysCoconut,項目名稱:moco,代碼行數:27,代碼來源:Main.java

示例11: MitMSOCKS4J

import net.sourceforge.argparse4j.ArgumentParsers; //導入依賴的package包/類
public MitMSOCKS4J() {
parser = ArgumentParsers.newArgumentParser("mitmsocks4j").description("Strips SSL/TLS layer from SOCKS proxy connection to dump plain data!");

parser.addArgument("-l", "--loglevel").required(false).nargs("?").choices("ALL", "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "OFF")
	.help("Sets logging level!").setDefault("OFF");

parser.addArgument("-x", "--proxyport").required(false).nargs("?").help("Proxy port that proxy listens.(default:" + DEFAULT_PROXY_PORT + ")")
	.type(Integer.class).setDefault(DEFAULT_PROXY_PORT);
parser.addArgument("-d", "--delegatorport").required(false).nargs("?")
	.help("Delegator port that mitm takes place.(default:" + DEFAULT_DELEGATOR_PORT + ")").type(Integer.class).setDefault(DEFAULT_DELEGATOR_PORT);
parser.addArgument("-s", "--securedports").required(false).nargs("*").help("Secured ports that will be ssl-stripped").type(Integer.class)
	.setDefault(FeatureControl.SUPPRESS);
parser.addArgument("-k", "--keystore").required(false).help("Keystore that will be used to imitate actual server certificates for clients(default:"+DEFAULT_KEYSTORE+")")
	.setDefault(DEFAULT_KEYSTORE);
parser.addArgument("-p", "--password").required(false).help("Keystore password.(default:"+DEFAULT_PASSWORD+")").setDefault(DEFAULT_PASSWORD);
   }
 
開發者ID:Akdeniz,項目名稱:mitmsocks4j,代碼行數:17,代碼來源:MitMSOCKS4J.java

示例12: main

import net.sourceforge.argparse4j.ArgumentParsers; //導入依賴的package包/類
/**
 * Main function demonstrating command-line processing via argparse4j.
 *
 * @param arguments Command-line arguments.
 */
public static void main(final String[] arguments)
{
   final ArgumentParser argumentParser =
      ArgumentParsers.newArgumentParser("Main", true);
   argumentParser.addArgument("-f", "--file")
                 .dest("file")
                 .required(true)
                 .help("Path and name of file");
   argumentParser.addArgument("-v", "--verbose")
                 .dest("verbose")
                 .type(Boolean.class)
                 .nargs("?")
                 .setConst(true)
                 .help("Enable verbose output.");

   try
   {
      final Namespace response = argumentParser.parseArgs(arguments);
      final String filePathAndName = response.getString("file");
      final Boolean verbositySet = response.getBoolean("verbose");
      out.println(
           "Path/name of file is '" + filePathAndName
         + "' and verbosity is "
         + (Boolean.TRUE.equals(verbositySet) ? "SET" : "NOT SET")
         + ".");
   }
   catch (ArgumentParserException parserEx)
   {
      argumentParser.handleError(parserEx);
   }
}
 
開發者ID:dustinmarx,項目名稱:java-cli-demos,代碼行數:37,代碼來源:Main.java

示例13: getArgumentParser

import net.sourceforge.argparse4j.ArgumentParsers; //導入依賴的package包/類
@Provides
@Singleton
ArgumentParser getArgumentParser(@Named("app-name") String appName,
                                 @Named("url-key") String urlKey) {
    ArgumentParser argumentParser = ArgumentParsers.newArgumentParser(appName)
            .defaultHelp(true)
            .description("Downloads HLS/M3U/M3U8 streams and combines them using ffmpeg.")
            .epilog("For additional questions and help, refer to https://github.com/TheGoodlike13/hls-downloader");

    argumentParser.addArgument("url").nargs("+")
            .dest(urlKey)
            .help(URL_EXPLANATION);

    return argumentParser;
}
 
開發者ID:TheGoodlike13,項目名稱:hls-downloader,代碼行數:16,代碼來源:ArgsModule.java

示例14: parseArgs

import net.sourceforge.argparse4j.ArgumentParsers; //導入依賴的package包/類
/**
 * Parse the input arguments and return the {@link Namespace} object.
 * @param args the input argument list
 * @return the parsed arguments as a {@link Namespace} object
 */
private static Namespace parseArgs(String[] args) {
	ArgumentParser parser = ArgumentParsers.newArgumentParser("Align")
			.defaultHelp(true)
			.description("Calculate the alignment of multiple structures");
	parser.addArgument("-a", "--align")
	.choices(CeCPMain.algorithmName, FatCatRigid.algorithmName, "DUMMY").setDefault(FatCatRigid.algorithmName)
	.help("Specify alignment method");
	parser.addArgument("-s", "--score")
	.choices("TM","RMSD").setDefault("TM")
	.help("Specify scoring method");
	parser.addArgument("-u", "--files").type(Boolean.class)
	.setDefault(false);
	parser.addArgument("-k", "--numclusts")
	.help("The number of clusters").setDefault(2);
	parser.addArgument("-c", "--cluster")
	.choices("PIC").setDefault("PIC")
	.help("Specify clustering method");
	parser.addArgument("pdbId").nargs("*")
	.help("The PDB Ids to consider");
	parser.addArgument("-z", "--sample").type(Double.class)
	.help("The sample of the PDB to take").setDefault(1.00);
	parser.addArgument("-l", "--minlength").type(Double.class)
	.help("The minimum length of each chain").setDefault(60);
	parser.addArgument("-t", "--threshold").type(Double.class)
	.help("The threshold to define an edge").setDefault(0.5);
	parser.addArgument("-f", "--hadoop")
	.help("The hadoop file to read from").setDefault(defaultPath);
	Namespace ns = null;
	try {
		ns = parser.parseArgs(args);
	} catch (ArgumentParserException e) {
		parser.handleError(e);
		System.exit(1);
	}
	return ns;
}
 
開發者ID:biojava,項目名稱:biojava-spark,代碼行數:42,代碼來源:ChainAligner.java

示例15: main

import net.sourceforge.argparse4j.ArgumentParsers; //導入依賴的package包/類
public static void main(String... args) throws Exception {

        ArgumentParser parser = ArgumentParsers.newArgumentParser("emoparser");
        parser.addArgument("server").required(true).help("server");
        parser.addArgument("emo-config").required(true).help("config.yaml");
        parser.addArgument("config-ddl").required(true).help("config-ddl.yaml");

        // Get the path to config-ddl
        Namespace result = parser.parseArgs(args);

        // Remove config-ddl arg
        new EmoService(result.getString("config-ddl"), new File(result.getString("emo-config")))
                .run((String[]) ArrayUtils.remove(args, 2));
    }
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:15,代碼來源:EmoService.java


注:本文中的net.sourceforge.argparse4j.ArgumentParsers類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。