private static void loadEnvironment(String[] args) { final String defaultConfDir = getProperty("dash.application.conf.dir"); final String defaultConfFile = (defaultConfDir != null ? defaultConfDir + File.separatorChar : "") + "conf.yml"; ArgumentParser parser = ArgumentParsers.newArgumentParser("Dash", true) .description("Runs a performance test mix.") .version("${prog} " + Version.id()) .epilog("Dash is a free software under Apache License Version 2.0"); parser .addArgument("-c", "--conf") .help("the config file containing the test specification to run (default: ../conf/conf.yml") .required(false) .setDefault(new File(defaultConfFile)) .type(File.class); parser .addArgument("-t", "--test") .help("the name of the test to run") .required(true) .type(String.class); parser .addArgument("-v", "--version") .help("print the version number") .action(Arguments.version()); try { YamlEnv yamlEnv = new YamlEnv(); Namespace namespace = parser.parseArgs(args); @SuppressWarnings("unchecked") HashMap<String, Object> env = (HashMap<String, Object>) yamlEnv.loadProperties((File) namespace.get("conf")); String test = namespace.getString("test"); @SuppressWarnings("unchecked") HashMap<String, Object> testSpec = (HashMap<String, Object>) env.get(test); if (testSpec == null) { System.err.println("Test spec (" + test + ") does not exist in the config file."); throw new Error(); // todo: message or log or exit } for (Map.Entry<String, Object> entry : testSpec.entrySet()) { if (entry.getValue() != null) { System.setProperty(entry.getKey(), entry.getValue().toString()); } } } catch (ArgumentParserException e) { parser.handleError(e); } catch (IOException e) { e.printStackTrace(); } }
public static void configureArguments(ArgumentParser parser) { parser.description("Trains a recommendation model and write it to disk."); ScriptEnvironment.configureArguments(parser); InputData.configureArguments(parser); parser .addArgument("-o", "--output-file") .type(File.class) .metavar("FILE") .setDefault("model.bin") .help("write trained model to FILE"); parser .addArgument("config") .type(File.class) .nargs("+") .metavar("CONFIG") .help("load algorithm configuration from CONFIG"); }
public static void configureArguments(ArgumentParser parser) { InputData.configureArguments(parser); ScriptEnvironment.configureArguments(parser); parser .addArgument("-c", "--config-file") .type(File.class) .action(Arguments.append()) .metavar("FILE") .help("use configuration from FILE"); parser .addArgument("-m", "--model-file") .type(File.class) .metavar("FILE") .help("load model from FILE"); parser.addArgument("--print-channel").metavar("CHAN").help("also print value from CHAN"); parser.addArgument("user").type(Long.class).metavar("USER").help("predict for USER"); parser .addArgument("items") .type(Long.class) .metavar("ITEM") .nargs("+") .help("predict for ITEMs"); }
private ArgumentParser buildParser(JarLocation location) { final String usage = "java -jar " + location; final ArgumentParser p = ArgumentParsers.newArgumentParser(usage, false); p.version( location .getVersion() .or( "No application version detected. Add a Implementation-Version " + "entry to your JAR's manifest to enable this.")); addHelp(p); p.addArgument("-v", "--version") .action(Arguments.help()) // never gets called; intercepted in #run .help("show the application version and exit"); return p; }
private void addHelp(ArgumentParser p) { p.addArgument("-h", "--help") .action(new SafeHelpAction(stdOut)) .help("show this help message and exit") .setDefault(Arguments.SUPPRESS); }
public ServiceParser(final String programName, final String description, final String... args) throws ArgumentParserException { final ArgumentParser parser = ArgumentParsers.newArgumentParser(programName).defaultHelp(true).description(description); nameArg = parser.addArgument("--name").setDefault(getHostName()).help("hostname to register as"); domainArg = parser .addArgument("--domain") .setDefault(ResolverConfReader.getDomainFromResolverConf("/etc/resolv.conf")) .help("Service registration domain."); serviceRegistryArg = parser .addArgument("--service-registry") .help("Service registry address. Overrides domain."); serviceRegistrarPluginArg = parser .addArgument("--service-registrar-plugin") .type(fileType().verifyExists().verifyCanRead()) .help("Service registration plugin."); zooKeeperConnectStringArg = parser.addArgument("--zk").setDefault("localhost:2181").help("zookeeper connection string"); zooKeeperSessiontimeoutArg = parser .addArgument("--zk-session-timeout") .type(Integer.class) .setDefault((int) SECONDS.toMillis(60)) .help("zookeeper session timeout"); zooKeeperConnectiontimeoutArg = parser .addArgument("--zk-connection-timeout") .type(Integer.class) .setDefault((int) SECONDS.toMillis(15)) .help("zookeeper connection timeout"); zooKeeperClusterId = parser .addArgument("--zk-cluster-id") .type(String.class) .setDefault((String) null) .help("Optional cluster ID to ensure we are connected to the right cluster"); noZooKeeperRegistrationArg = parser .addArgument("--no-zk-registration") .setDefault(SUPPRESS) .action(storeTrue()) .help("Do not register this master in zookeeper. Useful for debugging."); zooKeeperEnableAcls = parser .addArgument("--zk-enable-acls") .action(storeTrue()) .setDefault(false) .help("Enable zookeeper ACLs."); zooKeeperAclMasterUser = parser .addArgument("--zk-acl-master-user") .type(String.class) .setDefault("helios-master") .help("zookeeper ACL username used for masters."); zooKeeperAclAgentUser = parser .addArgument("--zk-acl-agent-user") .type(String.class) .setDefault("helios-agent") .help("zookeeper ACL username used for agents."); noMetricsArg = parser .addArgument("--no-metrics") .setDefault(SUPPRESS) .action(storeTrue()) .help("Turn off all collection and reporting of metrics"); statsdHostPortArg = parser .addArgument("--statsd-host-port") .setDefault((String) null) .help( "host:port of where to send statsd metrics " + "(to be useful, --no-metrics must *NOT* be specified)"); riemannHostPortArg = parser .addArgument("--riemann-host-port") .setDefault((String) null) .help( "host:port of where to send riemann events and metrics " + "(to be useful, --no-metrics must *NOT* be specified)"); verboseArg = parser.addArgument("-v", "--verbose").action(Arguments.count()); syslogArg = parser.addArgument("--syslog").help("Log to syslog.").action(storeTrue()); logconfigArg = parser .addArgument("--logconfig") .type(fileType().verifyExists().verifyCanRead()) .help("Logback configuration file."); noLogSetupArg = parser.addArgument("--no-log-setup").action(storeTrue()).help(SUPPRESS); sentryDsnArg = parser .addArgument("--sentry-dsn") .setDefault((String) null) .help("The sentry data source name"); kafkaArg = parser .addArgument("--kafka") .action(append()) .setDefault(new ArrayList<String>()) .help("Kafka brokers to bootstrap with"); stateDirArg = parser .addArgument("--state-dir") .setDefault(".") .help("Directory for persisting state locally."); ffwdEnabled = parser .addArgument("--ffwd-enabled") .action(storeTrue()) .setDefault(false) .help( "Enables reporting of metrics to FastForward. " + "Only functional when --no-metrics is not set."); ffwdAddress = parser .addArgument("--ffwd-address") .help( "Overrides the default FastForward address, " + "should contain host and port like `host:port`."); ffwdInterval = parser .addArgument("--ffwd-interval-secs") .type(Integer.class) .setDefault(30) .help("Interval in seconds at which to report metrics to FastForward."); ffwdMetricKey = parser .addArgument("--ffwd-key") .setDefault(programName) .help( "Value to use for `key` in metric data sent to FastForward. " + "Defaults to '" + programName + "'"); addArgs(parser); try { this.options = parser.parseArgs(args); } catch (ArgumentParserException e) { parser.handleError(e); throw e; } }