當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。