当前位置: 首页>>代码示例>>Java>>正文


Java JCommander类代码示例

本文整理汇总了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);
   }
}
 
开发者ID:dustinmarx,项目名称:java-cli-demos,代码行数:26,代码来源:Main.java

示例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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:32,代码来源:Arguments.java

示例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;
	}
}
 
开发者ID:georghinkel,项目名称:ttc2017smartGrids,代码行数:20,代码来源:Main.java

示例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();

	}
 
开发者ID:georghinkel,项目名称:ttc2017smartGrids,代码行数:17,代码来源:App.java

示例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;
}
 
开发者ID:deB4SH,项目名称:Byter,代码行数:20,代码来源:ComponentHelper.java

示例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);
}
 
开发者ID:deB4SH,项目名称:Byter,代码行数:27,代码来源:Launcher.java

示例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;
}
 
开发者ID:line,项目名称:centraldogma,代码行数:22,代码来源:Main.java

示例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);
  }
}
 
开发者ID:joshelser,项目名称:accumulo-delimited-ingest,代码行数:17,代码来源:ArgumentParser.java

示例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);
}
 
开发者ID:google,项目名称:devtools-driver,代码行数:23,代码来源:SafariDriver.java

示例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;
}
 
开发者ID:deB4SH,项目名称:Byter,代码行数:24,代码来源:ComponentHelper.java

示例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();
  }

}
 
开发者ID:apache,项目名称:incubator-ratis,代码行数:26,代码来源:Runner.java

示例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;
}
 
开发者ID:deB4SH,项目名称:Byter,代码行数:25,代码来源:ComponentHelper.java

示例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());
}
 
开发者ID:deB4SH,项目名称:Byter,代码行数:20,代码来源:JmxNetworkManagerTest.java

示例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);
    }
}
 
开发者ID:clearwsd,项目名称:clearwsd,代码行数:17,代码来源:WordSenseCLI.java

示例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;
     }
 }
 
开发者ID:olehmberg,项目名称:winter,代码行数:24,代码来源:Executable.java


注:本文中的com.beust.jcommander.JCommander类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。