net.sourceforge.argparse4j.ArgumentParsers Java Examples

The following examples show how to use net.sourceforge.argparse4j.ArgumentParsers. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImpressionsToInfluxDb.java    From seldon-server with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #2
Source File: JobListCommandTest.java    From helios with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
  // use a real, dummy Subparser impl to avoid having to mock out every single call
  final ArgumentParser parser = ArgumentParsers.newArgumentParser("test");
  final Subparser subparser = parser.addSubparsers().addParser("list");
  command = new JobListCommand(subparser);

  when(client.jobs()).thenReturn(Futures.immediateFuture(jobs));

  final Map<JobId, JobStatus> statuses = new HashMap<>();
  for (final JobId jobId : jobs.keySet()) {
    // pretend each job is deployed
    final JobStatus status = JobStatus.newBuilder()
        .setDeployments(ImmutableMap.of("host", Deployment.of(jobId, Goal.START)))
        .build();
    statuses.put(jobId, status);
  }

  when(client.jobStatuses(jobs.keySet())).thenReturn(Futures.immediateFuture(statuses));
}
 
Example #3
Source File: Generate.java    From graphicsfuzz with Apache License 2.0 6 votes vote down vote up
private static Namespace parse(String[] args) throws ArgumentParserException {
  ArgumentParser parser = ArgumentParsers.newArgumentParser("Generate")
      .defaultHelp(true)
      .description("Generate a shader.");

  // Required arguments
  parser.addArgument("reference-json")
      .help("Input reference shader json file.")
      .type(File.class);

  parser.addArgument("donors")
      .help("Path of folder of donor shaders.")
      .type(File.class);

  parser.addArgument("output")
      .help("Output shader job file file (.json).")
      .type(File.class);

  addGeneratorCommonArguments(parser);

  return parser.parseArgs(args);

}
 
Example #4
Source File: Mutate.java    From graphicsfuzz with Apache License 2.0 6 votes vote down vote up
private static Namespace parse(String[] args) throws ArgumentParserException {
  ArgumentParser parser = ArgumentParsers.newArgumentParser("Mutate")
      .defaultHelp(true)
      .description("Takes a shader, gives back a mutated shader.");

  // Required arguments
  parser.addArgument("input")
      .help("A .frag or .vert shader")
      .type(File.class);

  parser.addArgument("output")
      .help("Path of mutated shader.")
      .type(File.class);

  parser.addArgument("--seed")
      .help("Seed (unsigned 64 bit long integer) for the random number generator.")
      .type(String.class);

  return parser.parseArgs(args);
}
 
Example #5
Source File: Main.java    From graphicsfuzz with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
  ArgumentParser parser = ArgumentParsers.newArgumentParser("Fuzzer server")
      .defaultHelp(true);

  parser.addArgument("--port")
      .help("Port on which to listen.")
      .setDefault(8080)
      .type(Integer.class);

  try {
    Namespace ns = parser.parseArgs(args);

    new FuzzerServer(ns.get("port")).start();

  } catch (ArgumentParserException ex) {
    ex.getParser().handleError(ex);
  }
}
 
Example #6
Source File: JobCreateCommandTest.java    From helios with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
  // use a real, dummy Subparser impl to avoid having to mock out every single call
  final ArgumentParser parser = ArgumentParsers.newArgumentParser("test");
  final Subparser subparser = parser.addSubparsers().addParser("create");

  final Supplier<Map<String, String>> envVarSupplier = new Supplier<Map<String, String>>() {
    @Override
    public Map<String, String> get() {
      return ImmutableMap.copyOf(envVars);
    }
  };

  command = new JobCreateCommand(subparser, envVarSupplier);

  when(client.createJob(argThat(matchesName(JOB_NAME)))).thenReturn(immediateFuture(
      new CreateJobResponse(CreateJobResponse.Status.OK,
          Collections.<String>emptyList(),
          "12345")
  ));
}
 
Example #7
Source File: PrettyPrint.java    From graphicsfuzz with Apache License 2.0 6 votes vote down vote up
private static Namespace parse(String[] args) throws ArgumentParserException {
  ArgumentParser parser = ArgumentParsers.newArgumentParser("PrettyPrint")
      .defaultHelp(true)
      .description("Pretty print a shader.");

  // Required arguments
  parser.addArgument("shader")
      .help("Path of shader to be pretty-printed.")
      .type(File.class);

  parser.addArgument("output")
      .help("Target file name.")
      .type(String.class);

  parser.addArgument("--add-braces")
      .help("Add braces even for single-statement code blocks")
      .action(Arguments.storeTrue());

  return parser.parseArgs(args);

}
 
Example #8
Source File: Main.java    From graphicsfuzz with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
  ArgumentParser parser = ArgumentParsers.newArgumentParser("Fuzzer server")
      .defaultHelp(true);

  parser.addArgument("--port")
      .help("Port on which to listen.")
      .setDefault(8080)
      .type(Integer.class);

  try {
    Namespace ns = parser.parseArgs(args);

    ShaderJobFileOperations fileOps = new ShaderJobFileOperations();

    new FuzzerServer(ns.get("port"), fileOps).start();

  } catch (ArgumentParserException ex) {
    ex.getParser().handleError(ex);
  }
}
 
Example #9
Source File: CompareHistograms.java    From graphicsfuzz with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws ArgumentParserException, FileNotFoundException {

    final ArgumentParser parser = ArgumentParsers.newArgumentParser("CompareHistograms")
        .defaultHelp(true)
        .description("Print chi-squared distance between the histograms of two given images.");

    // Required arguments
    parser.addArgument("image1")
        .help("Path of first image.")
        .type(File.class);
    parser.addArgument("image2")
        .help("Path of second image.")
        .type(File.class);

    final Namespace ns = parser.parseArgs(args);

    System.out.println(ImageUtil.compareHistograms((File) ns.get("image1"), ns.get("image2")));

  }
 
Example #10
Source File: ComparePsnr.java    From graphicsfuzz with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws ArgumentParserException, FileNotFoundException {

    final ArgumentParser parser = ArgumentParsers.newArgumentParser("ComparePsnr")
        .defaultHelp(true)
        .description("Print PSNR for two images.");

    // Required arguments
    parser.addArgument("image1")
        .help("Path of first image.")
        .type(File.class);
    parser.addArgument("image2")
        .help("Path of second image.")
        .type(File.class);

    final Namespace ns = parser.parseArgs(args);

    System.out.println(ImageUtil.comparePsnr(ns.get("image1"), ns.get("image2")));

  }
 
Example #11
Source File: FragmentShaderToShaderJob.java    From graphicsfuzz with Apache License 2.0 6 votes vote down vote up
private static Namespace parse(String[] args) throws ArgumentParserException {
  ArgumentParser parser = ArgumentParsers.newArgumentParser("FragmentShaderToShaderJob")
      .defaultHelp(true)
      .description("Turns a fragment shader into a shader job with randomized uniforms and "
          + "(if needed) a suitable vertex shader.");

  // Required arguments
  parser.addArgument("shader")
      .help("Path of .frag shader to be turned into a shader job.")
      .type(File.class);

  parser.addArgument("output")
      .help("Target shader job .json file.")
      .type(String.class);

  parser.addArgument("--seed")
      .help("Seed (unsigned 64 bit long integer) for the random number generator.")
      .type(String.class);

  return parser.parseArgs(args);
}
 
Example #12
Source File: FragmentShaderJobToVertexShaderJob.java    From graphicsfuzz with Apache License 2.0 6 votes vote down vote up
private static Namespace parse(String[] args) throws ArgumentParserException {
  ArgumentParser parser = ArgumentParsers.newArgumentParser("FragmentShaderToShaderJob")
      .defaultHelp(true)
      .description("Turns a fragment shader into a shader job with randomized uniforms and "
          + "(if needed) a suitable vertex shader.");

  // Required arguments
  parser.addArgument("shader")
      .help("Path of .frag shader to be turned into a shader job.")
      .type(File.class);

  parser.addArgument("output")
      .help("Target shader job .json file.")
      .type(String.class);

  parser.addArgument("--seed")
      .help("Seed (unsigned 64 bit long integer) for the random number generator.")
      .type(String.class);

  return parser.parseArgs(args);
}
 
Example #13
Source File: AdlChecker.java    From archie with Apache License 2.0 6 votes vote down vote up
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"));
}
 
Example #14
Source File: UpgradeShadingLanguageVersion.java    From graphicsfuzz with Apache License 2.0 6 votes vote down vote up
private static Namespace parse(String[] args) throws ArgumentParserException {
  ArgumentParser parser = ArgumentParsers.newArgumentParser("UpgradeShadingLanguageVersion")
      .defaultHelp(true)
      .description("Upgrade shading language version.");

  // Required arguments
  parser.addArgument("shader")
      .help("Path of shader to be upgraded.")
      .type(File.class);

  parser.addArgument("output")
      .help("Target file name.")
      .type(String.class);

  // Optional arguments
  parser.addArgument("--norename")
      .help("Do not rename user-defined variables and functions")
      .action(Arguments.storeTrue());

  return parser.parseArgs(args);
}
 
Example #15
Source File: PredictionsToInfluxDb.java    From seldon-server with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #16
Source File: SynthesizeFile.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
public static void main(String... args) throws Exception {
  ArgumentParser parser =
      ArgumentParsers.newFor("SynthesizeFile")
          .build()
          .defaultHelp(true)
          .description("Synthesize a text file or ssml file.");
  MutuallyExclusiveGroup group = parser.addMutuallyExclusiveGroup().required(true);
  group.addArgument("--text").help("The text file from which to synthesize speech.");
  group.addArgument("--ssml").help("The ssml file from which to synthesize speech.");

  try {
    Namespace namespace = parser.parseArgs(args);

    if (namespace.get("text") != null) {
      synthesizeTextFile(namespace.getString("text"));
    } else {
      synthesizeSsmlFile(namespace.getString("ssml"));
    }
  } catch (ArgumentParserException e) {
    parser.handleError(e);
  }
}
 
Example #17
Source File: PredictionApi.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
public static void argsHelper(String[] args, PrintStream out) throws IOException {
  ArgumentParser parser =
      ArgumentParsers.newFor("PredictionApi")
          .build()
          .defaultHelp(true)
          .description("Prediction API Operation");

  Subparsers subparsers = parser.addSubparsers().dest("command");

  Subparser predictParser = subparsers.addParser("predict");
  predictParser.addArgument("modelId");
  predictParser.addArgument("filePath");

  String projectId = System.getenv("PROJECT_ID");
  String computeRegion = System.getenv("REGION_NAME");

  Namespace ns = null;
  try {
    ns = parser.parseArgs(args);
    if (ns.get("command").equals("predict")) {
      predict(projectId, computeRegion, ns.getString("modelId"), ns.getString("filePath"));
    }
  } catch (ArgumentParserException e) {
    parser.handleError(e);
  }
}
 
Example #18
Source File: HiveScriptGenerator.java    From emodb with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #19
Source File: MainCli.java    From Repeat with Apache License 2.0 6 votes vote down vote up
private ArgumentParser setupParser() {
	ArgumentParser parser = ArgumentParsers.newFor("Repeat").build()
               .defaultHelp(true)
               .description("Execute Repeat operations in the terminal.");
	parser.addArgument("-s", "--host").type(String.class)
			.setDefault("localhost")
			.help("Specify a custom host at which the Repeat server is running.");
	parser.addArgument("-p", "--port").type(Integer.class)
			.help("Specify a custom port at which the Repeat server is running."
					+ "If not specified, port value is read from config file.");

	Subparsers subParsers = parser.addSubparsers().help("Help for each individual command.");
       for (CliActionProcessor processor : processors.values()) {
       	processor.addArguments(subParsers);
       }

       return parser;
}
 
Example #20
Source File: CommandLine.java    From dockerfile-image-update with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
static ArgumentParser getArgumentParser() {
    ArgumentParser parser = ArgumentParsers.newFor("dockerfile-image-update").addHelp(true).build()
            .description("Image Updates through Pull Request Automator");

    parser.addArgument("-o", "--" + Constants.GIT_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", "--" + Constants.GIT_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;
}
 
Example #21
Source File: ImportProductSets.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
public static void argsHelper(String[] args, PrintStream out) throws Exception {
  ArgumentParser parser = ArgumentParsers.newFor("Import Product Sets").build();
  Subparsers subparsers = parser.addSubparsers().dest("command");

  Subparser importProductSetsParser = subparsers.addParser("import_product_sets");
  importProductSetsParser.addArgument("gcsUri");

  String projectId = System.getenv("PROJECT_ID");
  String computeRegion = System.getenv("REGION_NAME");

  Namespace ns = null;
  try {
    ns = parser.parseArgs(args);
    if (ns.get("command").equals("import_product_sets")) {
      importProductSets(projectId, computeRegion, ns.getString("gcsUri"));
    }
  } catch (ArgumentParserException e) {
    parser.handleError(e);
  }
}
 
Example #22
Source File: ZookeeperReadyCommand.java    From common-docker with Apache License 2.0 6 votes vote down vote up
private static ArgumentParser createArgsParser() {
  ArgumentParser zkReady = ArgumentParsers
      .newArgumentParser(ZK_READY)
      .defaultHelp(true)
      .description("Check if ZK is ready.");

  zkReady.addArgument("zookeeper_connect")
      .action(store())
      .required(true)
      .type(String.class)
      .metavar("ZOOKEEPER_CONNECT")
      .help("Zookeeper connect string.");

  zkReady.addArgument("timeout")
      .action(store())
      .required(true)
      .type(Integer.class)
      .metavar("TIMEOUT_IN_MS")
      .help("Time (in ms) to wait for service to be ready.");

  return zkReady;
}
 
Example #23
Source File: KryoConsumerExample.java    From kafka-examples with Apache License 2.0 6 votes vote down vote up
/**
 * Get the command-line argument parser.
 */
private static ArgumentParser argParser() {
    ArgumentParser parser = ArgumentParsers
            .newArgumentParser("simple-producer")
            .defaultHelp(true)
            .description("This example is to demonstrate kafka producer capabilities");

    parser.addArgument("--bootstrap.servers").action(store())
            .required(true)
            .type(String.class)
            .metavar("BROKER-LIST")
            .help("comma separated broker list");

    parser.addArgument("--topic").action(store())
            .required(true)
            .type(String.class)
            .metavar("TOPIC")
            .help("produce messages to this topic");


    return parser;
}
 
Example #24
Source File: ModelApi.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
static void argsHelper(String[] args) {
  ArgumentParser parser =
      ArgumentParsers.newFor("ModelApi")
          .build()
          .defaultHelp(true)
          .description("Model API operations.");
  Subparsers subparsers = parser.addSubparsers().dest("command");

  Subparser createModelParser = subparsers.addParser("create_model");
  createModelParser.addArgument("datasetId");
  createModelParser.addArgument("modelName");
  createModelParser.addArgument("trainBudget");

  String projectId = System.getenv("GOOGLE_CLOUD_PROJECT");
  String computeRegion = System.getenv("REGION_NAME");

  if (projectId == null || computeRegion == null) {
    System.out.println("Set `GOOGLE_CLOUD_PROJECT` and `REGION_NAME` as specified in the README");
    System.exit(-1);
  }

  try {
    Namespace ns = parser.parseArgs(args);
    if (ns.get("command").equals("create_model")) {
      createModel(
          projectId,
          computeRegion,
          ns.getString("datasetId"),
          ns.getString("modelName"),
          ns.getString("trainBudget"));
    }
  } catch (ArgumentParserException e) {
    parser.handleError(e);
  }
}
 
Example #25
Source File: HostListCommandTest.java    From helios with Apache License 2.0 5 votes vote down vote up
private int runCommand(String... commandArgs)
    throws ExecutionException, InterruptedException, ArgumentParserException {

  final String[] args = new String[1 + commandArgs.length];
  args[0] = "hosts";
  System.arraycopy(commandArgs, 0, args, 1, commandArgs.length);

  // use a real, dummy Subparser impl to avoid having to mock out every single call
  final ArgumentParser parser = ArgumentParsers.newArgumentParser("test");
  final Subparser subparser = parser.addSubparsers().addParser("hosts");
  final HostListCommand command = new HostListCommand(subparser);

  final Namespace options = parser.parseArgs(args);
  return command.run(options, client, out, false, null);
}
 
Example #26
Source File: SynthesizeText.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
public static void main(String... args) throws Exception {

    ArgumentParser parser =
        ArgumentParsers.newFor("SynthesizeText")
            .build()
            .defaultHelp(true)
            .description("Synthesize a text, text with audio effect profiles, or ssml.");

    MutuallyExclusiveGroup group = parser.addMutuallyExclusiveGroup().required(true);
    group
        .addArgument("--text")
        .help("The text file from which to synthesize speech.")
        .nargs("+")
        .metavar("TEXT", "EFFECTSPROFILE(optional)");
    group.addArgument("--ssml").help("The ssml file from which to synthesize speech.");

    try {
      Namespace namespace = parser.parseArgs(args);

      if ((namespace.get("text") != null)) {
        if (namespace.getList("text").size() == 2) {
          synthesizeTextWithAudioProfile(
              namespace.getList("text").get(0).toString(),
              namespace.getList("text").get(1).toString());

        } else {
          synthesizeText(namespace.getString("text"));
        }

      } else {
        synthesizeSsml(namespace.getString("ssml"));
      }
    } catch (ArgumentParserException e) {
      parser.handleError(e);
    }
  }
 
Example #27
Source File: Arguments.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
private static ArgumentParser initializeArgumentParser() {
    final ArgumentParser parser = ArgumentParsers.newArgumentParser(PROGRAM_NAME);

    parser.addArgument("-i", toArgName(ACTIVE_CONNECTION_PARAMETER)).type(Boolean.class)
            .setDefault(false).help(ACTIVE_CONNECTION_HELP);
    parser.addArgument("-ho", toArgName(HOLD_TIMER_PARAMETER)).type(Integer.class)
            .setDefault(INITIAL_HOLD_TIME).help(INITIAL_HOLD_TIME_HELP);
    parser.addArgument("-pr", toArgName(PREFIXES_PARAMETER)).type(Integer.class)
            .setDefault(0).help(PREFIXES_PARAMETER_HELP);
    parser.addArgument("-sc", toArgName(SPEAKERS_COUNT)).type(Integer.class)
            .setDefault(0).help(SPEAKERS_COUNT_HELP);
    parser.addArgument("-mp", toArgName(MULTIPATH_PARAMETER)).type(Boolean.class)
            .setDefault(false).help(MULTIPATH_PARAMETER_HELP);
    parser.addArgument("-" + AS_PARAMETER, toArgName(AS_PARAMETER))
            .type((ArgumentTypeTool<AsNumber>) as -> new AsNumber(Uint32.valueOf(as)))
            .setDefault(new AsNumber(Uint32.valueOf(64496))).help(AS_PARAMETER_HELP);
    parser.addArgument("-ec", toArgName(EXTENDED_COMMUNITIES_PARAMETER))
            .type((ArgumentTypeTool<List<String>>) extComInput ->
                    Arrays.asList(extComInput.split(","))).setDefault(Collections.emptyList())
            .help(EXTENDED_COMMUNITIES_PARAMETER_HELP);
    parser.addArgument("-ll", toArgName(LOG_LEVEL))
            .type((ArgumentTypeTool<Level>) Level::toLevel).setDefault(Level.INFO).help("log levels");
    parser.addArgument("-ra", toArgName(REMOTE_ADDRESS_PARAMETER))
            .type((ArgumentTypeTool<List<InetSocketAddress>>) input ->
                    InetSocketAddressUtil.parseAddresses(input, DEFAULT_REMOTE_PORT))
            .setDefault(Collections.singletonList(REMOTE_ADDRESS))
            .help(REMOTE_ADDRESS_PARAMETER_HELP);
    parser.addArgument("-la", toArgName(LOCAL_ADDRESS_PARAMETER))
            .type((ArgumentTypeTool<InetSocketAddress>) input ->
                    getInetSocketAddress(input, DEFAULT_LOCAL_PORT))
            .setDefault(LOCAL_ADDRESS).help(LOCAL_ADDRESS_PARAMETER_HELP);
    return parser;
}
 
Example #28
Source File: Main.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * @return an ArgumentParser used to perform argument parsing
 */
private static ArgumentParser getParser()
{
	ArgumentParser parser = ArgumentParsers.newFor(Constants.APPLICATION_NAME).build().defaultHelp(false)
		.description("RPG Character Generator").version(PCGenPropBundle.getVersionNumber());

	parser.addArgument("-v", "--verbose").help("verbose logging").type(Boolean.class).action(Arguments.count());

	parser.addArgument("-V", "--version").action(Arguments.version());

	MutuallyExclusiveGroup startupMode =
			parser.addMutuallyExclusiveGroup().description("start up on a specific mode");

	startupMode.addArgument("--name-generator").help("run the name generator").type(Boolean.class)
		.action(Arguments.storeTrue());

	startupMode.addArgument("-D", "--tab").nargs(1);

	parser.addArgument("-s", "--settingsdir").nargs(1)
		.type(Arguments.fileType().verifyIsDirectory().verifyCanRead().verifyExists());
	parser.addArgument("-m", "--campaignmode").nargs(1).type(String.class);
	parser.addArgument("-E", "--exportsheet").nargs(1)
		.type(Arguments.fileType().verifyCanRead().verifyExists().verifyIsFile());

	parser.addArgument("-o", "--outputfile").nargs(1)
		.type(Arguments.fileType().verifyCanCreate().verifyCanWrite().verifyNotExists());

	parser.addArgument("-c", "--character").nargs(1)
		.type(Arguments.fileType().verifyCanRead().verifyExists().verifyIsFile());

	parser.addArgument("-p", "--party").nargs(1)
		.type(Arguments.fileType().verifyCanRead().verifyExists().verifyIsFile());

	return parser;
}
 
Example #29
Source File: BmpMockArguments.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
private static ArgumentParser initializeArgumentParser() {
    final ArgumentParser parser = ArgumentParsers.newArgumentParser(PROGRAM_NAME);
    parser.addArgument(toArgName(ROUTERS_COUNT_DST))
            .type(Integer.class)
            .setDefault(1);
    parser.addArgument(toArgName(PEERS_COUNT_DST))
            .type(Integer.class)
            .setDefault(0);
    parser.addArgument(toArgName(PRE_POLICY_ROUTES_COUNT_DST))
            .type(Integer.class)
            .setDefault(0);
    parser.addArgument(toArgName(POST_POLICY_ROUTES_COUNT_DST))
            .type(Integer.class).setDefault(0);
    parser.addArgument(toArgName(PASSIVE_MODE_DST))
            .action(Arguments.storeTrue());
    parser.addArgument(toArgName(LOCAL_ADDRESS_DST))
            .type((parser13, arg, value) -> getInetSocketAddress(value, DEFAULT_LOCAL_PORT))
            .setDefault(LOCAL_ADDRESS);
    parser.addArgument("-ra", toArgName(REMOTE_ADDRESS_DST))
            .type((ArgumentTypeTool<List<InetSocketAddress>>) input ->
                    InetSocketAddressUtil.parseAddresses(input, DEFAULT_REMOTE_PORT))
            .setDefault(Collections.singletonList(REMOTE_ADDRESS));
    parser.addArgument(toArgName(LOG_LEVEL_DST))
            .type((parser1, arg, value) -> Level.toLevel(value))
            .setDefault(Level.INFO);
    return parser;
}
 
Example #30
Source File: DeploymentGroupInspectCommandTest.java    From helios with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  // use a real, dummy Subparser impl to avoid having to mock out every single call
  final ArgumentParser parser = ArgumentParsers.newArgumentParser("test");
  final Subparser subparser = parser.addSubparsers().addParser("inspect");

  command = new DeploymentGroupInspectCommand(subparser);

  when(client.deploymentGroup(NAME)).thenReturn(Futures.immediateFuture(DEPLOYMENT_GROUP));
  final ListenableFuture<DeploymentGroup> nullFuture = Futures.immediateFuture(null);
  when(client.deploymentGroup(NON_EXISTENT_NAME)).thenReturn(nullFuture);
}