Java Code Examples for com.beust.jcommander.JCommander#parse()

The following examples show how to use com.beust.jcommander.JCommander#parse() . 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: CodeSampleParams.java    From googleads-java-lib with Apache License 2.0 6 votes vote down vote up
boolean parseArguments(String[] args, Runtime runtime,
    PrintStream usageStream) {
  JCommander jc = new JCommander(this);

  if (args.length == 0) {
    return false;
  }

  jc.parse(args);

  if (help) {
    StringBuilder usageOut = new StringBuilder();
    jc.usage(usageOut);
    usageStream.println(usageOut.toString());
    runtime.exit(0);
  }

  return true;
}
 
Example 2
Source File: DispatchSample.java    From director-sdk with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
  DispatchSample sample = new DispatchSample();

  JCommander jc = new JCommander(sample);
  jc.setProgramName("DispatchSample");

  try {
    jc.parse(args);

  } catch (ParameterException e) {
    System.err.println(e.getMessage());
    jc.usage();
    System.exit(ExitCodes.OK);
  }

  System.exit(sample.run());
}
 
Example 3
Source File: OffsetStatus.java    From mirus with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void main(String[] argv) {
  Args args = new Args();
  JCommander jCommander =
      JCommander.newBuilder()
          .programName(OffsetStatus.class.getSimpleName())
          .addObject(args)
          .build();
  try {
    jCommander.parse(argv);
  } catch (Exception e) {
    jCommander.usage();
    throw e;
  }
  if (args.help) {
    jCommander.usage();
    return;
  }
  new OffsetStatus(args).run();
}
 
Example 4
Source File: UPMiner.java    From api-mining with GNU General Public License v3.0 6 votes vote down vote up
public static void main(final String[] args) throws Exception {

		// Runtime parameters
		final Parameters params = new Parameters();
		final JCommander jc = new JCommander(params);

		try {
			jc.parse(args);

			// Mine project
			System.out.println("Processing " + FilenameUtils.getBaseName(params.arffFile) + "...");
			mineAPICallSequences(params.arffFile, params.outFolder, 0.2, 0.2, params.minSupp);

		} catch (final ParameterException e) {
			System.out.println(e.getMessage());
			jc.usage();
		}

	}
 
Example 5
Source File: ResizeClusterSample.java    From director-sdk with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
  ResizeClusterSample sample = new ResizeClusterSample();

  JCommander jc = new JCommander(sample);
  jc.setProgramName("ResizeClusterSample");

  try {
    jc.parse(args);

  } catch (ParameterException e) {
    System.err.println(e.getMessage());
    jc.usage();
    System.exit(ExitCodes.PARAMETER_EXCEPTION);
  }

  System.exit(sample.run());
}
 
Example 6
Source File: CodeSampleParams.java    From google-ads-java with Apache License 2.0 6 votes vote down vote up
boolean parseArguments(String[] args, Runtime runtime, PrintStream usageStream) {
  JCommander jc = new JCommander(this);

  if (args.length == 0) {
    return false;
  }

  jc.parse(args);

  if (help) {
    StringBuilder usageOut = new StringBuilder();
    jc.usage(usageOut);
    usageStream.println(usageOut.toString());
    runtime.exit(0);
  }

  return true;
}
 
Example 7
Source File: Clean.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public static Options parse(String[] cliArgs) {
  Options args = new Options();
  JCommander jc = JCommander.newBuilder()
    .addObject(args)
    .build();
  jc.setProgramName("dremio-admin clean");

  try {
    jc.parse(cliArgs);
  } catch (ParameterException p) {
    AdminLogger.log(p.getMessage());
    jc.usage();
    System.exit(1);
  }

  if(args.help){
    jc.usage();
  }
  return args;
}
 
Example 8
Source File: FlowDocumentationTool.java    From nomulus with Apache License 2.0 6 votes vote down vote up
/** Parses command line flags and then runs the documentation tool. */
public static void main(String[] args) {
  FlowDocumentationTool docTool = new FlowDocumentationTool();
  JCommander jcommander = new JCommander(docTool);
  jcommander.setProgramName("flow_docs_tool");

  try {
    jcommander.parse(args);
  } catch (ParameterException e) {
    jcommander.usage();
    throw e;
  }

  if (docTool.displayHelp) {
    jcommander.usage();
    return;
  }

  docTool.run();
}
 
Example 9
Source File: GenerateWorkspaceOptionsTest.java    From migration-tooling with Apache License 2.0 5 votes vote down vote up
@Test
public void noCommaDelimiter() throws Exception {
  GenerateWorkspaceOptions options = new GenerateWorkspaceOptions();
  JCommander optionParser = JCommander.newBuilder().addObject(options).build();
  optionParser.parse("--artifact", "foo:bar:[1.2.3,)");
  assertThat(options.artifacts).contains("foo:bar:[1.2.3,)");
}
 
Example 10
Source File: Main.java    From walle with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
    final Map<String, IWalleCommand> subCommandList = new HashMap<String, IWalleCommand>();
    subCommandList.put("show", new ShowCommand());
    subCommandList.put("rm", new RemoveCommand());
    subCommandList.put("put", new PutCommand());
    subCommandList.put("batch", new BatchCommand());
    subCommandList.put("batch2", new Batch2Command());

    final WalleCommandLine walleCommandLine = new WalleCommandLine();
    final JCommander commander = new JCommander(walleCommandLine);

    for (Map.Entry<String, IWalleCommand> commandEntry : subCommandList.entrySet()) {
        commander.addCommand(commandEntry.getKey(), commandEntry.getValue());
    }
    try {
        commander.parse(args);
    } catch (ParameterException e) {
        System.out.println(e.getMessage());
        commander.usage();
        System.exit(1);
        return;
    }

    walleCommandLine.parse(commander);

    final String parseCommand = commander.getParsedCommand();
    if (parseCommand != null) {
        subCommandList.get(parseCommand).parse();
    }
}
 
Example 11
Source File: DLedgerConfigTest.java    From openmessaging-storage-dledger with Apache License 2.0 5 votes vote down vote up
@Test
public void testParseArguments() {
    DLedgerConfig dLedgerConfig = new DLedgerConfig();
    JCommander.Builder builder = JCommander.newBuilder().addObject(dLedgerConfig);
    JCommander jc = builder.build();
    jc.parse("-i", "n1", "-g", "test", "-p", "n1-localhost:21911", "-s", "/tmp");
    Assert.assertEquals("n1", dLedgerConfig.getSelfId());
    Assert.assertEquals("test", dLedgerConfig.getGroup());
    Assert.assertEquals("n1-localhost:21911", dLedgerConfig.getPeers());
    Assert.assertEquals("/tmp", dLedgerConfig.getStoreBaseDir());
}
 
Example 12
Source File: RegistryTestServerMain.java    From nomulus with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
  RegistryTestServerMain serverMain = new RegistryTestServerMain();
  JCommander jCommander = new JCommander(serverMain);
  jCommander.setProgramName("dr-run server");
  jCommander.parse(args);
  if (serverMain.help) {
    jCommander.usage();
    return;
  }
  serverMain.run();
}
 
Example 13
Source File: JCommanderPrefixTranslatorTest.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Test
public void testCollectionDelegatesPrefix() {
  final JCommanderPrefixTranslator translator = new JCommanderPrefixTranslator();
  final ArgumentsCollection args = new ArgumentsCollection();
  args.argChildren.add(new ArgumentChildren());
  args.argChildren.add(new ArgumentChildrenOther());
  translator.addObject(args);
  final JCommanderTranslationMap map = translator.translate();
  final JCommander commander = prepareCommander(map);
  commander.parse("--arg", "5", "--arg2", "blah");
  map.transformToOriginal();
  Assert.assertEquals("5", ((ArgumentChildren) args.argChildren.get(0)).arg);
  Assert.assertEquals("blah", ((ArgumentChildrenOther) args.argChildren.get(1)).arg2);
}
 
Example 14
Source File: IrisAbstractApplication.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
public static void exec(Class<? extends IrisAbstractApplication> appClazz, Collection<Class<? extends Module>> modules, String... args) {
   Arguments arguments = new Arguments();
   JCommander jc = new JCommander(arguments);
   jc.setAcceptUnknownOptions(true);
   try {
      jc.parse(args);
   }
   catch(RuntimeException e) {
      System.out.println("Error parsing arguments: " + e.getMessage());
      jc.usage();
      System.exit(-1);
   }

   exec(appClazz, modules, arguments);
}
 
Example 15
Source File: GenerateWorkspaceOptionsTest.java    From migration-tooling with Apache License 2.0 5 votes vote down vote up
@Test
public void multipleRepositories() throws Exception {
  GenerateWorkspaceOptions options = new GenerateWorkspaceOptions();
  JCommander optionParser = JCommander.newBuilder().addObject(options).build();
  optionParser.parse(
      "--repositories", "http://central.maven.org/maven2/,http://repo.spring.io/libs-milestone/");
  assertThat(options.repositories)
      .containsExactly(
          "http://central.maven.org/maven2/", "http://repo.spring.io/libs-milestone/");
}
 
Example 16
Source File: ParameterizedExecutable.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
/** Checks if usage should be displayed, if not calls run. */
private void parseArgs(String[] args) throws Exception {
  JCommander jc = new JCommander(this);
  jc.parse(args);
  if (help) {
    jc.usage();
  }
}
 
Example 17
Source File: FoldSourceFileVSMLines.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(final String[] args) {

		final Parameters params = new Parameters();
		final JCommander jc = new JCommander(params);

		try {
			jc.parse(args);
			foldSourceFileVSMLines(params.file, params.compressionRatio, params.outFile);
		} catch (final ParameterException e) {
			System.out.println(e.getMessage());
			jc.usage();
		}

	}
 
Example 18
Source File: Configuration.java    From elasticsearch with Apache License 2.0 5 votes vote down vote up
public Configuration(String... args) {
    final JCommander jCommander = new JCommander();
    jCommander.addObject(zookeeperCLI);
    jCommander.addObject(elasticsearchCLI);
    jCommander.addObject(this);
    try {
        jCommander.parse(args); // Parse command line args into configuration class.
    } catch (com.beust.jcommander.ParameterException ex) {
        System.out.println(ex);
        jCommander.setProgramName("(Options preceded by an asterisk are required)");
        jCommander.usage();
        throw ex;
    }
}
 
Example 19
Source File: Main.java    From akka-tutorial with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
	
	CommandMaster commandMaster = new CommandMaster();
       CommandSlave commandSlave = new CommandSlave();
       JCommander jCommander = JCommander.newBuilder()
       	.addCommand(MasterSystem.MASTER_ROLE, commandMaster)
           .addCommand(SlaveSystem.SLAVE_ROLE, commandSlave)
           .build();
       
       try {
       	jCommander.parse(args);

           if (jCommander.getParsedCommand() == null)
               throw new ParameterException("No command given.");

           switch (jCommander.getParsedCommand()) {
               case MasterSystem.MASTER_ROLE:
               	ConfigurationSingleton.get().update(commandMaster);
               	DatasetDescriptorSingleton.get().update(commandMaster);
               	
               	MasterSystem.start();
                   break;
               case SlaveSystem.SLAVE_ROLE:
               	ConfigurationSingleton.get().update(commandSlave);
               	DatasetDescriptorSingleton.set(null);
               	
               	SlaveSystem.start();
                   break;
               default:
                   throw new AssertionError();
           }
       } catch (ParameterException e) {
           System.out.printf("Could not parse args: %s\n", e.getMessage());
           if (jCommander.getParsedCommand() == null) {
               jCommander.usage();
           } else {
               jCommander.usage(jCommander.getParsedCommand());
           }
           System.exit(1);
       }
}
 
Example 20
Source File: S4Submitter.java    From samoa with Apache License 2.0 4 votes vote down vote up
@Override
	public void deployTask(Task task) {
		// TODO: Get application FROM HTTP server
		// TODO: Initializa a http server to serve the app package
		
		String appURIString = null;
//		File app = new File(System.getProperty("user.dir")
//				+ "/src/site/dist/SAMOA-S4-0.1-dist.jar");
		
		// TODO: String app url http://localhost:8000/SAMOA-S4-0.1-dist.jar
		try {
			URL appURL = new URL("http://localhost:8000/SAMOA-S4-0.1.jar");
			appURIString = appURL.toString();
		} catch (MalformedURLException e1) {
			e1.printStackTrace();
		}
		
//		try {
//			appURIString = app.toURI().toURL().toString();
//		} catch (MalformedURLException e) {
//			e.printStackTrace();
//		}
		if (task == null) {
			logger.error("Can't execute since evaluation task is not set!");
			return;
		} else {
			logger.info("Deploying SAMOA S4 task [{}] from location [{}]. ",
					task.getClass().getSimpleName(), appURIString);
		}

		String[] args = { "-c=testCluster2",
				"-appClass=" + S4DoTask.class.getName(),
				"-appName=" + "samoaApp",
				"-p=evalTask=" + task.getClass().getSimpleName(),
				"-zk=localhost:2181", "-s4r=" + appURIString , "-emc=" + SamoaSerializerModule.class.getName()};
		// "-emc=" + S4MOAModule.class.getName(),
		// "@" +
		// Resources.getResource("s4moa.properties").getFile(),

		S4Config s4config = new S4Config();
		JCommander jc = new JCommander(s4config);
		jc.parse(args);

		Map<String, String> namedParameters = new HashMap<String, String>();
		for (String parameter : s4config.namedParameters) {
			String[] param = parameter.split("=");
			namedParameters.put(param[0], param[1]);
		}

		AppConfig config = new AppConfig.Builder()
				.appClassName(s4config.appClass).appName(s4config.appName)
				.appURI(s4config.appURI).namedParameters(namedParameters)
				.build();

		DeploymentUtils.initAppConfig(config, s4config.clusterName, true,
				s4config.zkString);

		System.out.println("Suposedly deployed on S4");
	}