Package com.beust.jcommander

Examples of com.beust.jcommander.JCommander


   */
  public static void main(String[] args) {
    NGrinderAgentStarter starter = new NGrinderAgentStarter();
    final NGrinderAgentStarterParam param = new NGrinderAgentStarterParam();
    checkJavaVersion();
    JCommander commander = new JCommander(param);
    commander.setProgramName("ngrinder-agent");
    commander.setAcceptUnknownOptions(true);
    try {
      commander.parse(args);
    } catch (Exception e) {
      LOG.error(e.getMessage());
      return;
    }
    final List<String> unknownOptions = commander.getUnknownOptions();
    modeParam = param.getModeParam();
    modeParam.parse(unknownOptions.toArray(new String[unknownOptions.size()]));

    if (modeParam.version != null) {
      System.out.println("nGrinder v" + getStaticVersion());
View Full Code Here


  private final Help help;
  private final JCommander jc;

  Main(Logger console) {
    this.console = console;
    this.jc = new JCommander(this);
    this.help = new Help(jc, console);

    jc.setProgramName(PROGRAM_NAME);
    jc.addCommand("help", help, "-h", "-help", "--help");
    jc.addCommand("run", new RunCommand(console, getConf()));
View Full Code Here

      console.info("\n  See '{} help <command>' for more information on a " +
          "specific command.", Main.PROGRAM_NAME);

    } else {
      for (String cmd : helpCommands) {
        JCommander commander = jc.getCommands().get(cmd);
        if (commander == null) {
          console.error("Unknown command: {}", cmd);
          return 1;
        }

        console.info("\nUsage: {} [general options] {} {} [command options]",
            new Object[] {
                Main.PROGRAM_NAME, cmd,
                commander.getMainParameterDescription()});
        console.info("\n  Description:");
        console.info("\n    {}", jc.getCommandDescription(cmd));
        if (!commander.getParameters().isEmpty()) {
          console.info("\n  Command options:\n");
          for (ParameterDescription param : commander.getParameters()) {
            hasRequired = printOption(console, param) || hasRequired;
          }
          if (hasRequired) {
            console.info("\n  * = required");
          }
        }
        List<String> examples = ((Command) commander.getObjects().get(0)).getExamples();
        if (examples != null) {
          console.info("\n  Examples:");
          for (String example : examples) {
            if (example.startsWith("#")) {
              // comment
View Full Code Here

  @VisibleForTesting
  final JCommander jc;

  Main(Logger console) {
    this.console = console;
    this.jc = new JCommander(this);
    this.help = new Help(jc, console);
    jc.setProgramName(DEFAULT_PROGRAM_NAME);
    jc.addCommand("help", help, "-h", "-help", "--help");
    jc.addCommand("create", new CreateDatasetCommand(console));
    jc.addCommand("copy", new CopyCommand(console));
View Full Code Here

      console.info("\n  See '{} help <command>' for more information on a " +
          "specific command.", programName);

    } else {
      for (String cmd : helpCommands) {
        JCommander commander = jc.getCommands().get(cmd);
        if (commander == null) {
          console.error("Unknown command: {}", cmd);
          return 1;
        }

        console.info("\nUsage: {} [general options] {} {} [command options]",
            new Object[] {
                programName, cmd,
                commander.getMainParameterDescription()});
        console.info("\n  Description:");
        console.info("\n    {}", jc.getCommandDescription(cmd));
        if (!commander.getParameters().isEmpty()) {
          console.info("\n  Command options:\n");
          for (ParameterDescription param : commander.getParameters()) {
            hasRequired = printOption(console, param) || hasRequired;
          }
          if (hasRequired) {
            console.info("\n  * = required");
          }
        }
        List<String> examples = ((Command) commander.getObjects().get(0)).getExamples();
        if (examples != null) {
          console.info("\n  Examples:");
          for (String example : examples) {
            if (example.startsWith("#")) {
              // comment
View Full Code Here

    }

    private List<String> processOptions(String[] args) {
        JSLintFlags jslintFlags = new JSLintFlags();
        Flags flags = new Flags();
        JCommander jc = new JCommander(new Object[] { flags , jslintFlags });
        jc.setProgramName(FULL_PROGRAM_NAME);
        try {
            jc.parse(args);
        } catch (ParameterException e) {
            info(e.getMessage());
            usage(jc);
        }
        if (flags.version) {
            version();
        }
        if (flags.help) {
            usage(jc);
        }
        if (flags.encoding != null) {
            encoding = flags.encoding;
        }
        lint = makeLint(flags);
        setResultFormatter(flags.report);
        for (ParameterDescription pd : jc.getParameters()) {
            Parameterized p = pd.getParameterized();
            // Is it declared on JSLintFlags?
            if (!pd.getObject().getClass().isAssignableFrom(JSLintFlags.class)) {
                continue;
            }
View Full Code Here

  public void suppressSystemExit() {
    suppressSystemExit = true;
  }
 
  public boolean start(String[] args) {
    JCommander parser = null;
    try {

      parser = new JCommander(this);
     
      addCommands(parser);
     
      try {
        parser.parse(args);
      }
      catch(Exception e) {
        failAndPrintUsage(e.toString());
      }

      if (help) {
        String cmd = parser.getParsedCommand();
        if (cmd == null) {
          parser.usage();
        }
        else {
          parser.usage(cmd);
        }             
      }
      else {
       
        Runnable cmd = commands.get(parser.getParsedCommand());
         
        if (cmd == null) {
          failAndPrintUsage();
        }
        else {
          cmd.run();
        }       
      }     
     
      if (suppressSystemExit) {
        return true;
      }
      else {
        System.exit(0);
      }
    }
    catch(CommandAbortedError error) {
      for(String m: error.messages) {
        logError(m);
      }
      if (error.printUsage && parser != null) {
        if (parser.getParsedCommand() != null) {
          parser.usage(parser.getParsedCommand());
        }
        else {
          parser.usage();
        }
      }
    }
    catch(Throwable e) {
      e.printStackTrace();
View Full Code Here

    m_executionListeners.add(l);
  }

  private static void usage() {
    if (m_jCommander == null) {
      m_jCommander = new JCommander(new CommandLineArgs());
    }
    m_jCommander.usage();
  }
View Full Code Here

    //
    // Parse the arguments
    //
    try {
      CommandLineArgs cla = new CommandLineArgs();
      m_jCommander = new JCommander(cla, argv);
      validateCommandLineParameters(cla);
      result.configure(cla);
    }
    catch(ParameterException ex) {
      exitWithError(ex.getMessage());
View Full Code Here

    return parse(args) && process();
  }

  private boolean parse(String[] args) {
    try {
      new JCommander(this, args);
      return true;
    } catch (ParameterException e) {
      System.err.println("Arguments parse error: " + e.getMessage());
      printUsage();
      return false;
View Full Code Here

TOP

Related Classes of com.beust.jcommander.JCommander

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.