当前位置: 首页>>代码示例>>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;未经允许,请勿转载。