本文整理汇总了Java中com.beust.jcommander.JCommander类的典型用法代码示例。如果您正苦于以下问题:Java JCommander类的具体用法?Java JCommander怎么用?Java JCommander使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JCommander类属于com.beust.jcommander包,在下文中一共展示了JCommander类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processCommandLineArguments
import com.beust.jcommander.JCommander; //导入依赖的package包/类
/**
* Use JCommander to process the provided command-line arguments.
* This method is an instance method (not static) to allow JCommander
* to use this instance's JCommander-annotated fields.
*
* @param arguments Command-line arguments.
*/
private void processCommandLineArguments(final String[] arguments)
{
final JCommander commander
= JCommander.newBuilder()
.programName("JCommander Demonstration")
.addObject(this)
.verbose(1)
.build();
commander.parse(arguments);
if (help)
{
commander.usage();
}
else
{
out.println("The file name provided is '" + file + "' and verbosity is set to " + verbose);
}
}
示例2: parse
import com.beust.jcommander.JCommander; //导入依赖的package包/类
/**
* Parses command line arguments and populates this command line instance.
* <p>
* If the command line arguments include the "help" argument, or if the
* arguments have incorrect values or order, then usage information is
* printed to {@link System#out} and the program terminates.
*
* @param args
* the command line arguments
* @return an instance of the parsed arguments object
*/
public Arguments parse(String[] args) {
JCommander jCommander = new JCommander(this);
jCommander.setProgramName("jsonschema2pojo");
try {
jCommander.parse(args);
if (this.showHelp) {
jCommander.usage();
exit(EXIT_OKAY);
}
} catch (ParameterException e) {
System.err.println(e.getMessage());
jCommander.usage();
exit(EXIT_ERROR);
}
return this;
}
示例3: main
import com.beust.jcommander.JCommander; //导入依赖的package包/类
public static void main(String[] args) {
Main app = new Main();
JCommander jc = new JCommander(app);
try {
jc.parse(args);
} catch (ParameterException pe) {
System.err.println(pe.getMessage());
jc.usage();
return;
}
try {
app.run();
} catch (IOException e) {
e.printStackTrace();
jc.usage();
return;
}
}
示例4: main
import com.beust.jcommander.JCommander; //导入依赖的package包/类
public static void main(String[] args) {
App app = new App();
JCommander jc = new JCommander(app);
try {
jc.parse(args);
} catch (ParameterException pe) {
System.err.println(pe.getMessage());
jc.usage();
return;
}
app.build();
}
示例5: startCommander
import com.beust.jcommander.JCommander; //导入依赖的package包/类
public static Commander startCommander(final ExecutorService service){
//build arguments
final String configurationDirectory = System.getProperty("user.dir") + File.separator + "configurations" + File.separator + "test";
final String[] argv = new String[]{"-s","commander","-cfg",configurationDirectory};
final CliParameter params = new CliParameter();
JCommander jcommander = new JCommander();
JCommander.newBuilder().addObject(params)
.build()
.parse(argv);
//build client runnable
final Commander commander = new Commander(params,false);
final Thread commanderThread = new Thread(commander);
commanderThread.setDaemon(true);
log.log(Level.INFO, "done building commander and deamon thread object");
service.execute(commanderThread);
log.log(Level.INFO,"done submitting daemon thread to service pool");
ThreadManager.nap(3000);
return commander;
}
示例6: main
import com.beust.jcommander.JCommander; //导入依赖的package包/类
/**
* Main Method.
* @param argv passed arguments
*/
public static void main(final String... argv) {
Runtime.getRuntime().addShutdownHook( new Thread() {
@Override public void run() {
log.log(Level.INFO,"Received Shutdown Hook - Shuting down Server/Client");
if(client != null)
client.stopJmxConnector();
if(server != null)
server.stopJmxConnector();
if(commander != null)
commander.stopJmxConnector();
}
});
//globalArgs = argv;
final CliParameter params = new CliParameter();
jcommander = new JCommander();
JCommander.newBuilder().addObject(params)
.build()
.parse(argv);
new Launcher(params);
}
示例7: init
import com.beust.jcommander.JCommander; //导入依赖的package包/类
@Override
public synchronized void init(DaemonContext context) {
if (state != State.NONE) {
throw new IllegalStateException("initialized already");
}
final JCommander commander = new JCommander(this);
commander.setProgramName(getClass().getName());
commander.parse(context.getArguments());
if (help != null && help) {
commander.usage();
final DaemonController controller = context.getController();
if (controller != null) {
controller.fail();
}
return;
}
state = State.INITIALIZED;
}
示例8: parse
import com.beust.jcommander.JCommander; //导入依赖的package包/类
public ArgumentParsingResult parse(String[] args) {
DelimitedIngestArguments argsPojo = new DelimitedIngestArguments();
try {
JCommander jcommander = new JCommander(argsPojo, args);
// If the user requested help, print it and then signal to terminate the app.
if (argsPojo.isHelp()) {
jcommander.usage();
return ArgumentParsingResult.terminate(argsPojo);
}
return ArgumentParsingResult.successful(argsPojo);
} catch (Exception e) {
return ArgumentParsingResult.failed(e);
}
}
示例9: main
import com.beust.jcommander.JCommander; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
WebDriverMain.getTmpIOSFolder(); // Ensures logging directory exists.
SafariIOSServerConfiguration options = new SafariIOSServerConfiguration();
new JCommander(options).parse(args);
SafariBrowserLauncher launcher;
if (options.getIsSimulator()) {
launcher = SafariBrowserLauncher.onSimulator(true);
} else {
RealDeviceHost.Configuration hostConf = RealDeviceHost.withDeveloperDiskImagesFromXcode();
if (!options.supervisionCert.isEmpty() && !options.supervisionKey.isEmpty()) {
hostConf =
hostConf.withSupervisionIdentity(
Paths.get(options.supervisionCert), Paths.get(options.supervisionKey));
} else if (options.supervisionCert.isEmpty() != options.supervisionKey.isEmpty()) {
throw new IllegalArgumentException("Supervision cert passed without key, or vice-versa");
}
launcher = SafariBrowserLauncher.onRealDevice(hostConf.initialize());
}
WebDriverMain.run(options, launcher);
}
示例10: startClient
import com.beust.jcommander.JCommander; //导入依赖的package包/类
/**
* Start Client as Thread inside a ExecutorService.
* @param service service to start in
* @return running Client object
*/
public static Client startClient(final ExecutorService service){
//build arguments
final String[] argv = new String[]{"-s","client"};
final CliParameter params = new CliParameter();
JCommander jcommander = new JCommander();
JCommander.newBuilder().addObject(params)
.build()
.parse(argv);
//build client runnable
final Client clientObj = new Client(params,false);
final Thread clientThread = new Thread(clientObj);
clientThread.setDaemon(true);
log.log(Level.INFO, "done building client and deamon thread object");
service.execute(clientThread);
log.log(Level.INFO,"done submitting daemon thread to service pool");
ThreadManager.nap(3000);
return clientObj;
}
示例11: main
import com.beust.jcommander.JCommander; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
initializeCommands();
Runner runner = new Runner();
Server server = new Server();
JCommander.Builder builder = JCommander.newBuilder().addObject(runner);
commands.forEach(command -> builder
.addCommand(command.getClass().getSimpleName().toLowerCase(), command));
JCommander jc = builder.build();
try {
jc.parse(args);
Optional<SubCommandBase> selectedCommand = commands.stream().filter(
command -> command.getClass().getSimpleName().toLowerCase()
.equals(jc.getParsedCommand())).findFirst();
if (selectedCommand.isPresent()) {
selectedCommand.get().run();
} else {
jc.usage();
}
} catch (ParameterException exception) {
System.err.println("Wrong parameters: " + exception.getMessage());
jc.usage();
}
}
示例12: startServer
import com.beust.jcommander.JCommander; //导入依赖的package包/类
/**
* Start Server as Thread inside a ExecutorService.
* @param service service to start in
* @return running Server object
*/
public static Server startServer(final ExecutorService service){
//build arguments
final String[] argv = new String[]{"-s","server"};
final CliParameter params = new CliParameter();
JCommander jcommander = new JCommander();
JCommander.newBuilder().addObject(params)
.build()
.parse(argv);
//build server runnable
final Server serverObj = new Server(params,false);
final Thread serverThread = new Thread(serverObj);
serverThread.setDaemon(true);
log.log(Level.INFO, "done building server and deamon thread object");
//start inside service
service.execute(serverThread);
log.log(Level.INFO,"done submitting daemon thread to service pool");
ThreadManager.nap(3000);
return serverObj;
}
示例13: startup
import com.beust.jcommander.JCommander; //导入依赖的package包/类
/**
* Start Method for everything related to this Test-Case.
*/
@BeforeClass
public static void startup(){
//set up test-space if not already done
FileManager.createFolder(testSpaceDir);
//build arguments
final String[] argv = new String[]{"-s","server"};
final CliParameter params = new CliParameter();
jcommander = new JCommander();
JCommander.newBuilder().addObject(params)
.build()
.parse(argv);
//build service
service = Executors.newFixedThreadPool(1);
serverObj = ComponentHelper.startServer(service);
log.log(Level.INFO, "JmxNetworkManagerTest running on port: " + serverObj.getConnectorSystemPort());
}
示例14: WordSenseCLI
import com.beust.jcommander.JCommander; //导入依赖的package包/类
WordSenseCLI(String[] args) {
cmd = new JCommander(this);
cmd.setProgramName(WordSenseCLI.class.getSimpleName());
try {
cmd.parse(args);
if (help || args.length == 0) {
System.out.println(helpMessage);
cmd.usage();
System.exit(0);
}
} catch (ParameterException e) {
System.err.println(e.getMessage());
cmd.usage();
System.exit(1);
}
}
示例15: parseCommandLine
import com.beust.jcommander.JCommander; //导入依赖的package包/类
protected boolean parseCommandLine(Class<?> cls, String... args) {
try {
if(!silent) {
System.err.println(BuildInfo.getJarPath(getClass()));
System.err.println(String.format("%s version %s", cls.getName(), BuildInfo.getBuildTimeString(cls)));
System.err.println(" __ __.___ __ ");
System.err.println(" / \\ / \\ | _____/ |_ ____ _______ ");
System.err.println(" \\ \\/\\/ / |/ \\ __\\/ __ \\ \\_ __ \\");
System.err.println(" \\ /| | | \\ | \\ ___/ | | \\/");
System.err.println(" \\__/\\ / |___|___| /__| \\___ > /\\ |__| ");
System.err.println(" \\/ \\/ \\/ \\/ ");
}
@SuppressWarnings("unused")
JCommander cmd = new JCommander(this, args);
return true;
} catch(Exception e) {
System.err.println(e.getMessage());
usage(args);
return false;
}
}