Java Code Examples for net.sourceforge.argparse4j.inf.ArgumentParser#addMutuallyExclusiveGroup()

The following examples show how to use net.sourceforge.argparse4j.inf.ArgumentParser#addMutuallyExclusiveGroup() . 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: KafkaReadyCommand.java    From common-docker with Apache License 2.0 4 votes vote down vote up
private static ArgumentParser createArgsParser() {
  ArgumentParser kafkaReady = ArgumentParsers
      .newArgumentParser(KAFKA_READY)
      .defaultHelp(true)
      .description("Check if Kafka is ready.");

  kafkaReady.addArgument("min-expected-brokers")
      .action(store())
      .required(true)
      .type(Integer.class)
      .metavar("MIN_EXPECTED_BROKERS")
      .help("Minimum number of brokers to wait for.");

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

  kafkaReady.addArgument("--config", "-c")
      .action(store())
      .type(String.class)
      .metavar("CONFIG")
      .help("List of bootstrap brokers.");

  MutuallyExclusiveGroup kafkaOrZK = kafkaReady.addMutuallyExclusiveGroup();
  kafkaOrZK.addArgument("--bootstrap-servers", "-b")
      .action(store())
      .type(String.class)
      .metavar("BOOTSTRAP_SERVERS")
      .help("List of bootstrap brokers.");

  kafkaOrZK.addArgument("--zookeeper-connect", "-z")
      .action(store())
      .type(String.class)
      .metavar("ZOOKEEPER_CONNECT")
      .help("Zookeeper connect string.");

  kafkaReady.addArgument("--security-protocol", "-s")
      .action(store())
      .type(String.class)
      .metavar("SECURITY_PROTOCOL")
      .setDefault("PLAINTEXT")
      .help("Which endpoint to connect to ? ");

  return kafkaReady;
}
 
Example 2
Source File: Main.java    From signal-cli with GNU General Public License v3.0 4 votes vote down vote up
private static Namespace parseArgs(String[] args) {
    ArgumentParser parser = ArgumentParsers.newFor("signal-cli")
            .build()
            .defaultHelp(true)
            .description("Commandline interface for Signal.")
            .version(BaseConfig.PROJECT_NAME + " " + BaseConfig.PROJECT_VERSION);

    parser.addArgument("-v", "--version")
            .help("Show package version.")
            .action(Arguments.version());
    parser.addArgument("--config")
            .help("Set the path, where to store the config (Default: $XDG_DATA_HOME/signal-cli , $HOME/.local/share/signal-cli).");

    MutuallyExclusiveGroup mut = parser.addMutuallyExclusiveGroup();
    mut.addArgument("-u", "--username")
            .help("Specify your phone number, that will be used for verification.");
    mut.addArgument("--dbus")
            .help("Make request via user dbus.")
            .action(Arguments.storeTrue());
    mut.addArgument("--dbus-system")
            .help("Make request via system dbus.")
            .action(Arguments.storeTrue());

    Subparsers subparsers = parser.addSubparsers()
            .title("subcommands")
            .dest("command")
            .description("valid subcommands")
            .help("additional help");

    final Map<String, Command> commands = Commands.getCommands();
    for (Map.Entry<String, Command> entry : commands.entrySet()) {
        Subparser subparser = subparsers.addParser(entry.getKey());
        entry.getValue().attachToSubparser(subparser);
    }

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

    if ("link".equals(ns.getString("command"))) {
        if (ns.getString("username") != null) {
            parser.printUsage();
            System.err.println("You cannot specify a username (phone number) when linking");
            System.exit(2);
        }
    } else if (!ns.getBoolean("dbus") && !ns.getBoolean("dbus_system")) {
        if (ns.getString("username") == null) {
            parser.printUsage();
            System.err.println("You need to specify a username (phone number)");
            System.exit(2);
        }
        if (!PhoneNumberFormatter.isValidNumber(ns.getString("username"), null)) {
            System.err.println("Invalid username (phone number), make sure you include the country code.");
            System.exit(2);
        }
    }
    if (ns.getList("recipient") != null && !ns.getList("recipient").isEmpty() && ns.getString("group") != null) {
        System.err.println("You cannot specify recipients by phone number and groups at the same time");
        System.exit(2);
    }
    return ns;
}
 
Example 3
Source File: Main.java    From lancoder with GNU General Public License v3.0 4 votes vote down vote up
private static Namespace parse(String[] args) {
	ArgumentParser parser = ArgumentParsers.newArgumentParser("lancoder")
			.defaultHelp(false)
			.version("${prog} " + LANCODER_VERSION);
	parser.addArgument("--version", "-V")
			.action(Arguments.version())
			.help("show the current version and exit");
	parser.addArgument("--verbose", "-v")
			.action(Arguments.count())
			.help("Increase verbosity. Default is level 3. '-vvvvvv' will be the most verbose,"
					+ " '-v' will be the less verbose.");

	MutuallyExclusiveGroup group = parser.addMutuallyExclusiveGroup()
			.required(true)
			.description("Run a master or worker instance");
	group.addArgument("--worker", "-w")
			.action(Arguments.storeTrue())
			.help("run the worker");
	group.addArgument("--master", "-m")
			.action(Arguments.storeTrue())
			.help("run the master");

	MutuallyExclusiveGroup group2 = parser.addMutuallyExclusiveGroup();
	group2.addArgument("--init-prompt", "-i")
			.action(Arguments.storeTrue())
			.help("intialize configuration and prompt user");
	group2.addArgument("--init-default", "-I")
			.action(Arguments.storeTrue())
			.help("initialize default config and exit");

	parser.addArgument("--debug", "-d")
			.action(Arguments.storeTrue())
			.help("Run lancoder in debug mode. Does not delete parts files after remuxing.");
	parser.addArgument("--config", "-c")
			.help("specify the config file");
	parser.addArgument("--overwrite", "-o")
			.action(Arguments.storeTrue())
			.help("if flag is set, overwrite old config");

	return parser.parseArgsOrFail(args);
}