Package com.gitblit.utils.cli

Examples of com.gitblit.utils.cli.CmdLineParser


   *             if the command line arguments were invalid.
   * @see Option
   * @see Argument
   */
  protected void parseCommandLine(Object options) throws UnloggedFailure {
    final CmdLineParser clp = newCmdLineParser(options);
    try {
      clp.parseArgument(argv);
    } catch (IllegalArgumentException err) {
      if (!clp.wasHelpRequestedByOption()) {
        throw new UnloggedFailure(1, "fatal: " + err.getMessage());
      }
    } catch (CmdLineException err) {
      if (!clp.wasHelpRequestedByOption()) {
        throw new UnloggedFailure(1, "fatal: " + err.getMessage());
      }
    }

    if (clp.wasHelpRequestedByOption()) {
      CommandMetaData meta = getClass().getAnnotation(CommandMetaData.class);
      String title = meta.name().toUpperCase() + ": " + meta.description();
      String b = com.gitblit.utils.StringUtils.leftPad("", title.length() + 2, '═');
      StringWriter msg = new StringWriter();
      msg.write('\n');
      msg.write(b);
      msg.write('\n');
      msg.write(' ');
      msg.write(title);
      msg.write('\n');
      msg.write(b);
      msg.write("\n\n");
      msg.write("USAGE\n");
      msg.write("─────\n");
      msg.write(' ');
      msg.write(commandName);
      msg.write('\n');
      msg.write("  ");
      clp.printSingleLineUsage(msg, null);
      msg.write("\n\n");
      String txt = getUsageText();
      if (!StringUtils.isEmpty(txt)) {
        msg.write(txt);
        msg.write("\n\n");
      }
      msg.write("ARGUMENTS & OPTIONS\n");
      msg.write("───────────────────\n");
      clp.printUsage(msg, null);
      msg.write('\n');
      String examples = usage().trim();
      if (!StringUtils.isEmpty(examples)) {
        msg.write('\n');
        msg.write("EXAMPLES\n");
View Full Code Here


    }
  }

  /** Construct a new parser for this command's received command line. */
  protected CmdLineParser newCmdLineParser(Object options) {
    return new CmdLineParser(options);
  }
View Full Code Here

   *             if the command line arguments were invalid.
   * @see Option
   * @see Argument
   */
  protected void parseCommandLine(Object options) throws UnloggedFailure {
    final CmdLineParser clp = newCmdLineParser(options);
    try {
      clp.parseArgument(argv);
    } catch (IllegalArgumentException err) {
      if (!clp.wasHelpRequestedByOption()) {
        throw new UnloggedFailure(1, "fatal: " + err.getMessage());
      }
    } catch (CmdLineException err) {
      if (!clp.wasHelpRequestedByOption()) {
        throw new UnloggedFailure(1, "fatal: " + err.getMessage());
      }
    }

    if (clp.wasHelpRequestedByOption()) {
      CommandMetaData meta = getClass().getAnnotation(CommandMetaData.class);
      String title = meta.name().toUpperCase() + ": " + meta.description();
      String b = com.gitblit.utils.StringUtils.leftPad("", title.length() + 2, '═');
      StringWriter msg = new StringWriter();
      msg.write('\n');
      msg.write(b);
      msg.write('\n');
      msg.write(' ');
      msg.write(title);
      msg.write('\n');
      msg.write(b);
      msg.write("\n\n");
      msg.write("USAGE\n");
      msg.write("─────\n");
      msg.write(' ');
      msg.write(commandName);
      msg.write('\n');
      msg.write("  ");
      clp.printSingleLineUsage(msg, null);
      msg.write("\n\n");
      String txt = getUsageText();
      if (!StringUtils.isEmpty(txt)) {
        msg.write(txt);
        msg.write("\n\n");
      }
      msg.write("ARGUMENTS & OPTIONS\n");
      msg.write("───────────────────\n");
      clp.printUsage(msg, null);
      msg.write('\n');
      String examples = usage().trim();
      if (!StringUtils.isEmpty(examples)) {
        msg.write('\n');
        msg.write("EXAMPLES\n");
View Full Code Here

    }
  }

  /** Construct a new parser for this command's received command line. */
  protected CmdLineParser newCmdLineParser(Object options) {
    return new CmdLineParser(options);
  }
View Full Code Here

TOP

Related Classes of com.gitblit.utils.cli.CmdLineParser

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.