Java 类org.kohsuke.args4j.ParserProperties 实例源码

项目:pgcodekeeper    文件:CliArgs.java   
private void printUsage(PrintWriter writer) {
    // fix defaults for options like help and other 0-arg booleans
    OptionHandlerRegistry.getRegistry().registerHandler(Boolean.class, BooleanNoDefOptionHandler.class);
    OptionHandlerRegistry.getRegistry().registerHandler(boolean.class, BooleanNoDefOptionHandler.class);

    ParserProperties prop = ParserProperties.defaults()
            .withUsageWidth(80)
            .withOptionSorter(null);

    ByteArrayOutputStream buf = new ByteArrayOutputStream();

    // new args instance to get correct defaults
    new CmdLineParser(new CliArgs(), prop)
    .printUsage(new OutputStreamWriter(buf, StandardCharsets.UTF_8), null);

    writer.println(MessageFormat.format(Messages.UsageHelp.replace("${tab}", "\t"),
            new String(buf.toByteArray(), StandardCharsets.UTF_8),
            DangerStatementOptionHandler.getMetaVariable() + '\n' + DbObjTypeOptionHandler.getMetaVariable()));
}
项目:monsoon    文件:Exporter.java   
public Exporter(String[] args) {
    final CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withUsageWidth(80));
    try {
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        System.err.println(e.getMessage());
        print_usage_and_exit_(parser);
        /* UNREACHABLE */
    }

    // If help is requested, simply print that.
    if (help) {
        print_usage_and_exit_(parser);
        /* UNREACHABLE */
    }

    // If there are no files, comlain with a non-zero exit code.
    if (dir == null)
        System.exit(EX_USAGE);

    dirPath = FileSystems.getDefault().getPath(dir);
}
项目:monsoon    文件:ApiBin.java   
public ApiBin(String[] args) {
    final CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withUsageWidth(80));
    try {
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        System.err.println(e.getMessage());
        print_usage_and_exit_(parser);
        /* UNREACHABLE */
    }

    // If help is requested, simply print that.
    if (help) {
        print_usage_and_exit_(parser);
        /* UNREACHABLE */
    }
}
项目:monsoon    文件:RhistMain.java   
/**
 * Initialize the verifier, using command-line arguments.
 *
 * @param args The command-line arguments passed to the program.
 */
public RhistMain(String[] args) {
    final CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withUsageWidth(80));
    try {
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        System.err.println(e.getMessage());
        print_usage_and_exit_(parser);
        /* UNREACHABLE */
    }

    // If help is requested, simply print that.
    if (help) {
        print_usage_and_exit_(parser);
        /* UNREACHABLE */
    }

    // If there are no files, comlain with a non-zero exit code.
    if (dir == null)
        System.exit(EX_USAGE);

    path_ = FileSystems.getDefault().getPath(dir);
}
项目:monsoon    文件:Verify.java   
/**
 * Initialize the verifier, using command-line arguments.
 * @param args The command-line arguments passed to the program.
 */
public Verify(String[] args) {
    final CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withUsageWidth(80));
    try {
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        System.err.println(e.getMessage());
        print_usage_and_exit_(parser);
        /* UNREACHABLE */
    }

    // If help is requested, simply print that.
    if (help) {
        print_usage_and_exit_(parser);
        /* UNREACHABLE */
    }

    // If there are no files, comlain with a non-zero exit code.
    if (files.isEmpty())
        System.exit(EX_USAGE);
}
项目:amidst    文件:Amidst.java   
private static void parseCommandLineArgumentsAndRun(String[] args) {
    CommandLineParameters parameters = new CommandLineParameters();
    AmidstMetaData metadata = createMetadata();
    CmdLineParser parser = new CmdLineParser(
            parameters,
            ParserProperties.defaults().withShowDefaults(false).withUsageWidth(120).withOptionSorter(null));
    try {
        parser.parseArgument(args);
        run(parameters, metadata, parser);
    } catch (CmdLineException e) {
        System.out.println(metadata.getVersion().createLongVersionString());
        System.err.println(e.getMessage());
        parser.printUsage(System.out);
        System.exit(2);
    }
}
项目:boildown    文件:Boil.java   
private final void doMain(String... args) throws Exception {
    final ParserProperties properties = ParserProperties.defaults()
        .withUsageWidth(80)
        .withShowDefaults(true);
    final CmdLineParser parser = new CmdLineParser(this, properties);
    try {
        parser.parseArgument(args);
        final int enabledBoilers = (zlib_ ? 1:0) + (lzf_ ? 1:0) + (snappy_ ? 1:0);
        if (compress_ == null && decompress_ == null) {
            throw new IllegalArgumentException("Missing '--compress' or '--decompress' " +
                "argument.");
        } else if (compress_ != null && decompress_ != null) {
            throw new IllegalArgumentException("Must specify only one of '--compress' or " +
                "'--decompress' arguments.");
        } else if (enabledBoilers > 1) {
            throw new IllegalArgumentException("Can only specify one of --zlib, --lzf, or --snappy.");
        } else if (enabledBoilers == 0) {
            throw new IllegalArgumentException("Must specify at least one of --zlib, --lzf, or --snappy.");
        }
        run(); // Go!
    } catch (Exception e) {
        log.debug("Failed to start; see usage.", e);
        parser.printUsage(System.err);
    }
}
项目:axisviewer    文件:AxisViewer.java   
private void doMain(final String[] args) throws Exception {
    final ParserProperties properties = ParserProperties.defaults().withUsageWidth(80);
    final CmdLineParser parser = new CmdLineParser(this, properties);
    try {
        parser.parseArgument(args);
        if (_url == null) {
            throw new CmdLineException(parser, "URL to camera stream required.", null);
        }
        // http://1.0.0.6:8085/axis-cgi/jpg/image.cgi?resolution=640x480
        Camera axis = new Camera("Axis 2100 Network Camera", _url, "", "", Constants.REFRESH_RATE );

        CameraFrame frame = new CameraFrame( axis );
        frame.setVisible(true);
        frame.run();
    } catch (Exception e) {
        System.err.println("Usage:");
        parser.printUsage(System.err);
    }
}
项目:amidst    文件:Amidst.java   
private static void parseCommandLineArgumentsAndRun(String[] args) {
    CommandLineParameters parameters = new CommandLineParameters();
    AmidstMetaData metadata = createMetadata();
    CmdLineParser parser = new CmdLineParser(
            parameters,
            ParserProperties.defaults().withShowDefaults(false).withUsageWidth(120).withOptionSorter(null));
    try {
        parser.parseArgument(args);
        run(parameters, metadata, parser);
    } catch (CmdLineException e) {
        System.out.println(metadata.getVersion().createLongVersionString());
        System.err.println(e.getMessage());
        parser.printUsage(System.out);
        System.exit(2);
    }
}
项目:griffin    文件:Griffin.java   
/**
 * @param args the command line arguments
 * @throws java.io.IOException the exception
 * @throws java.lang.InterruptedException the exception
 */
public static void main(String[] args) throws IOException, InterruptedException {
    try {
        Griffin griffin = new Griffin();

        CmdLineParser parser = new CmdLineParser(griffin, ParserProperties.defaults().withUsageWidth(120));
        parser.parseArgument(args);

        if (griffin.help || griffin.version || args.length == 0) {
            griffin.printHelpMessage();
            parser.printUsage(System.out);
        }
        else {
            griffin.commands.execute();
        }
    }
    catch (CmdLineException ex) {
        Logger.getLogger(Griffin.class.getName()).log(Level.SEVERE, null, ex);
    }
}
项目:griffin    文件:PreviewCommand.java   
/**
 * Executes the command
 */
@Override
public void execute() {
    Griffin griffin = new Griffin();
    if (help) {
        System.out.println("Preview the site on the given port: default: 9090");
        System.out.println("usage: griffin preview [option]");
        System.out.println("Options: " + LINE_SEPARATOR);
        CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withUsageWidth(120));
        parser.printUsage(System.out);
    }
    else {
        griffin.printAsciiGriffin();
        griffin.preview(port);
    }
}
项目:griffin    文件:PublishCommand.java   
/**
 * Executes the command
 */
@Override
public void execute() {
    if (help) {
        System.out.println("Publish the content in the current Griffin directory.");
        System.out.println("usage: griffin publish [option]");
        System.out.println("Options: " + LINE_SEPARATOR);
        CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withUsageWidth(120));
        parser.printUsage(System.out);
        return;
    }
    try {
        Griffin griffin = new Griffin();
        griffin.printAsciiGriffin();
        griffin.publish(fastParse, rebuild);
        System.out.println("All done for now! I will be bach!");
    }
    catch (IOException | InterruptedException ex) {
        Logger.getLogger(PublishCommand.class.getName()).log(Level.SEVERE, null, ex);
    }
}
项目:griffin    文件:NewCommand.java   
/**
 * Executes the command
 */
@Override
public void execute() {
    try {

        if (help || args.isEmpty()) {
            System.out.println("Scaffold out a new Griffin directory structure.");
            System.out.println("usage: griffin new [option] <path>");
            System.out.println("Options: " + LINE_SEPARATOR);
            CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withUsageWidth(120));
            parser.printUsage(System.out);
            return;
        }
        else {
            filePath = Paths.get(args.get(0));
        }
        Griffin griffin = new Griffin(filePath.resolve(name));
        griffin.initialize(filePath, name);
        System.out.println("Successfully created new site.");
    }
    catch (IOException | URISyntaxException ex) {
        Logger.getLogger(NewCommand.class.getName()).log(Level.SEVERE, null, ex);
    }
}
项目:katas-sessions    文件:Options.java   
public static Options parse(final String[] args)
  throws IOException
{
  Options options = new Options();
  CmdLineParser parser = new CmdLineParser(options, ParserProperties.defaults().withUsageWidth(120));
  try {
    // parse the arguments.
    parser.parseArgument(args);

    if (options.arguments.isEmpty() || options.arguments.size() < 2 || options.showUsage) {
      usage(parser);
    }
  } catch (CmdLineException e) {
    System.err.println(e.getMessage());
    System.err.println();
    usage(parser);
  }

  return options;
}
项目:springapp    文件:Main.java   
public void doMain(String[] args) {

        ParserProperties props = ParserProperties.defaults().withUsageWidth(80);
        CmdLineParser parser = new CmdLineParser(this, props);
        try {
            parser.parseArgument(args);
            if (help) {
                System.err.println(format("java {0} [OPTIONS] [CONFIG...]", Main.class.getName()));
                parser.printUsage(System.err);
                return;
            }
        } catch (CmdLineException ex) {
            System.err.println(format("java {0} [OPTIONS] [CONFIG...]", Main.class.getName()));
            parser.printUsage(System.err);
            return;
        }

        startServer();
    }
项目:ProcGalaxy    文件:SimpleGalaxyGfx.java   
public static void main(String[] argv)
{
    Args args = new Args();
    CmdLineParser parser = new CmdLineParser(args,
            ParserProperties.defaults().withOptionSorter(null)
                .withUsageWidth(80).withShowDefaults(false));

    boolean wasExcept = false;
    try {
        parser.parseArgument(argv);
    }
    catch (CmdLineException e)
    {
        System.out.println(e.getMessage());
        wasExcept = true;
    }

    if (wasExcept || args.help)
    {

        System.out.println("java -jar prettygalaxy.v1.jar [options...]");
        parser.printUsage(System.out);

        System.exit(args.help?0:1);
    }

    args.sanitize();

    for (int i = 0; i < args.numRuns; i++)
    {
        generate(args);

        if (args.out == null)
            break;
    }
}
项目:ProcGalaxy    文件:NebulaStormGalaxyGfx.java   
public static void main(String[] argv)
{
    Args args = new Args();
    CmdLineParser parser = new CmdLineParser(args,
            ParserProperties.defaults().withOptionSorter(null)
                .withUsageWidth(80).withShowDefaults(false));

    boolean wasExcept = false;
    try {
        parser.parseArgument(argv);
    }
    catch (CmdLineException e)
    {
        System.out.println(e.getMessage());
        wasExcept = true;
    }

    if (wasExcept || args.help)
    {

        System.out.println("java -jar prettygalaxy.v1.jar [options...]");
        parser.printUsage(System.out);

        System.exit(args.help?0:1);
    }

    args.sanitize();

    for (int i = 0; i < args.numRuns; i++)
    {
        generate(args);

        if (args.out == null)
            break;
    }
}
项目:monsoon    文件:FileConvert.java   
public FileConvert(String[] args) {
    final CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withUsageWidth(80));
    try {
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        System.err.println(e.getMessage());
        print_usage_and_exit_(parser);
        /* UNREACHABLE */
    }

    // If help is requested, simply print that.
    if (help) {
        print_usage_and_exit_(parser);
        /* UNREACHABLE */
    }

    // If verbose mode is requested, dial up the log spam.
    if (verbose) {
        Logger.getLogger("com.groupon.lex").setLevel(Level.INFO);
        Logger.getLogger("com.github.groupon.monsoon").setLevel(Level.INFO);
    }

    // If there are no files, comlain with a non-zero exit code.
    if (srcdir == null)
        System.exit(EX_USAGE);

    srcdir_path_ = FileSystems.getDefault().getPath(srcdir);
}
项目:monsoon    文件:FileConvert.java   
/**
 * Initialize the verifier, using command-line arguments.
 *
 * @param args The command-line arguments passed to the program.
 */
public FileConvert(String[] args) {
    final CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withUsageWidth(80));
    try {
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        System.err.println(e.getMessage());
        print_usage_and_exit_(parser);
        /* UNREACHABLE */
    }

    // If help is requested, simply print that.
    if (help) {
        print_usage_and_exit_(parser);
        /* UNREACHABLE */
    }

    // If verbose mode is requested, dial up the log spam.
    if (verbose)
        Logger.getLogger("com.groupon.lex").setLevel(Level.INFO);

    // If there are no files, comlain with a non-zero exit code.
    if (srcdir == null || dstdir == null)
        System.exit(EX_USAGE);

    srcdir_path_ = FileSystems.getDefault().getPath(srcdir);
    dstdir_path_ = FileSystems.getDefault().getPath(dstdir);
}
项目:jmxlocal    文件:Command.java   
private static ParserProperties configure() {
    CmdLineParser.registerHandler(BuiltIn.class, AltEnumOptionHandler.class);
    ParserProperties properties = ParserProperties.defaults();
    properties.withOptionSorter(null);
    properties.withUsageWidth(100);
    return properties;
}
项目:sette-tool    文件:ArgumentParser.java   
/**
 * Parses and checks the program arguments. If the arguments are invalid or the user requested
 * the help message, this method returns <code>false</code> and writes the message for the user.
 * If the parsing is successful, this method does not print anything to the output.
 * 
 * @param args
 *            the arguments to parse
 * @return <code>true</code> if the arguments were successfully parsed, <code>false</code> if
 *         arguments are invalid or the user requested the help message (<code>false</code>
 *         generally means that SETTE should stop)
 */
public boolean parse(@NonNull String... args) {
    // register handler for tool and set the current configuration for it
    OptionHandlerRegistry.getRegistry().registerHandler(SetteToolConfiguration.class,
            ToolOptionHandler.class);
    ToolOptionHandler.configuration = configuration;

    // parse args with preset properties
    ParserProperties parserProps = ParserProperties.defaults()
            .withShowDefaults(true)
            .withUsageWidth(80);
    CmdLineParser parser = new CmdLineParser(this, parserProps);

    try {
        parser.parseArgument(args);

        if (help) {
            printHelp(parser);
            return false;
        } else {
            return true;
        }
    } catch (CmdLineException ex) {
        errorOutput.println(ex.getMessage());
        printHelp(parser);
        return false;
    }
}
项目:gaffer    文件:Gaffer.java   
private CmdLineParser getParser() {
  if (parser == null) {
    final ParserProperties properties = ParserProperties.defaults();
    properties.withUsageWidth(80);

    parser = new CmdLineParser(this, properties);
  }

  return parser;
}
项目:pengyifan-commons    文件:LibSVMPredictClient.java   
public void doMain(String[] args)
    throws IOException {
  // parse options
  ParserProperties.defaults().withUsageWidth(80);
  CmdLineParser parser = new CmdLineParser(this);

  try {
    parser.parseArgument(args);
  } catch (CmdLineException e) {
    System.err.println(USAGE);
    parser.printUsage(System.err);
    System.err.println();
    return;
  }

  if (arguments.size() != 3) {
    System.err.println(USAGE);
    parser.printUsage(System.err);
    System.err.println();
    return;
  }

  LibSVMPredict predict = new LibSVMPredict(
      new File(arguments.get(0)),
      new File(arguments.get(2)),
      new File(arguments.get(1)),
      probabilityEstimates,
      quiteMode
      );
  predict.predict();
}
项目:ethereum-secure-proxy    文件:CmdLineResult.java   
void printExample() {
    CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withShowDefaults(false));
    parser.printUsage(System.out);
}
项目:ProcGalaxy    文件:PlanetsGfx.java   
public static void main(String[] argv)
    {
        Args args = new Args();
        CmdLineParser parser = new CmdLineParser(args,
                ParserProperties.defaults().withOptionSorter(null)
                    .withUsageWidth(80).withShowDefaults(false));

        boolean wasExcept = false;
        try {
            parser.parseArgument(argv);
            validateArgs(args);
        }
        catch (CmdLineException e)
        {
            System.out.println(e.getMessage());
            wasExcept = true;
        }



        if (wasExcept || args.help)
        {

            System.out.println("java -jar PlanetGfx.v1.jar [options...]");
            parser.printUsage(System.out);

            System.exit(args.help?0:1);
        }

        for (int i = 0; i < args.numRuns; i++)
        {
            BufferedImage im = generate(args);

            if (args.out == null)
            {
                NebulaStormGalaxyGfx.showImage(im);
            } else
            {
                NebulaStormGalaxyGfx.saveImage(im, args.out);
            }
        }
//        NebulaStormGalaxyGfx.showImage(im);
    }
项目:jsonix-schema-compiler    文件:PartialCmdLineParser.java   
public PartialCmdLineParser(Object bean, ParserProperties parserProperties) {
    super(bean, parserProperties);
}
项目:es6draft    文件:Repl.java   
private static void parseOptions(Options options, String[] args) {
    ParserProperties properties = ParserProperties.defaults().withUsageWidth(128);
    CmdLineParser parser = new CmdLineParser(options, properties);
    try {
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        System.err.println(e.getMessage());
        System.err.println(getUsageString(parser, false));
        System.exit(1);
    }
    if (options.showVersion) {
        System.out.println(getVersionString());
        System.exit(0);
    }
    if (options.showHelp) {
        System.out.println(getUsageString(parser, false));
        System.exit(0);
    }
    if (options.showExtendedHelp) {
        System.out.println(getUsageString(parser, true));
        System.exit(0);
    }
    if (options.printCode || options.printCodeWithTypes || options.debugInfo) {
        // Disable interpreter when bytecode is requested
        options.noInterpreter = true;
    }
    if (options.fileName != null) {
        // Execute as last script
        if (options.fileName.toString().equals("-")) {
            // "-" is a short-hand to request reading from System.in
            if (System.console() == null) {
                // System.in is not interactive
                options.evalScripts.add(new EvalString(read(System.in)));
            } else {
                options.interactive = true;
            }
        } else {
            options.evalScripts.add(new EvalPath(options.fileName, EvalPath.Type.Script));
        }
    }
    if (options.evalScripts.isEmpty()) {
        // Default to interactive mode when no files or expressions were set
        options.interactive = true;
    }
}