Search in sources :

Example 81 with CmdLineException

use of org.kohsuke.args4j.CmdLineException in project hudson-2.x by hudson.

the class LoginCommand method run.

@Override
protected int run() throws Exception {
    Authentication a = Hudson.getAuthentication();
    if (a == Hudson.ANONYMOUS)
        // this causes CLI to show the command line options.
        throw new CmdLineException("No credentials specified.");
    ClientAuthenticationCache store = new ClientAuthenticationCache(channel);
    store.set(a);
    return 0;
}
Also used : Authentication(org.acegisecurity.Authentication) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 82 with CmdLineException

use of org.kohsuke.args4j.CmdLineException in project pinot by linkedin.

the class VerifySegmentState method main.

public static void main(String[] args) throws Exception {
    VerifySegmentState verifier = new VerifySegmentState();
    CmdLineParser cmdLineParser = new CmdLineParser(verifier);
    try {
        cmdLineParser.parseArgument(args);
    } catch (CmdLineException e) {
        LOGGER.error("Failed to read command line arguments: ", e);
        cmdLineParser.printUsage(System.err);
        System.exit(1);
    }
    verifier.execute();
}
Also used : CmdLineParser(org.kohsuke.args4j.CmdLineParser) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 83 with CmdLineException

use of org.kohsuke.args4j.CmdLineException in project gitblit by gitblit.

the class GitBlitServer4UITests method main.

public static void main(String... args) {
    GitBlitServer4UITests server = new GitBlitServer4UITests();
    // filter out the baseFolder parameter
    List<String> filtered = new ArrayList<String>();
    String folder = "data";
    for (int i = 0; i < args.length; i++) {
        String arg = args[i];
        if (arg.equals("--baseFolder")) {
            if (i + 1 == args.length) {
                System.out.println("Invalid --baseFolder parameter!");
                System.exit(-1);
            } else if (args[i + 1] != ".") {
                folder = args[i + 1];
            }
            i = i + 1;
        } else {
            filtered.add(arg);
        }
    }
    Params.baseFolder = folder;
    Params params = new Params();
    CmdLineParser parser = new CmdLineParser(params);
    try {
        parser.parseArgument(filtered);
        if (params.help) {
            server.usage(parser, null);
        }
    } catch (CmdLineException t) {
        server.usage(parser, t);
    }
    if (params.stop) {
        server.stop(params);
    } else {
        server.start(params);
    }
}
Also used : CmdLineParser(org.kohsuke.args4j.CmdLineParser) ArrayList(java.util.ArrayList) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 84 with CmdLineException

use of org.kohsuke.args4j.CmdLineException in project es6draft by anba.

the class Repl method parseOptions.

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.debug || options.fullDebug || 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));
        }
    }
    if (options.evalScripts.isEmpty()) {
        // Default to interactive mode when no files or expressions were set
        options.interactive = true;
        // Warn if --module is used without input files.
        if (options.module) {
            System.err.println(formatMessage("module_no_files"));
        }
    }
    if (options.ecmascript7) {
        System.err.println(formatMessage("deprecated.es7"));
    }
}
Also used : CmdLineParser(org.kohsuke.args4j.CmdLineParser) ParserProperties(org.kohsuke.args4j.ParserProperties) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 85 with CmdLineException

use of org.kohsuke.args4j.CmdLineException in project newts by OpenNMS.

the class MergeSort method createCmdLineParser.

private CmdLineParser createCmdLineParser() {
    return new CmdLineParser(this) {

        @SuppressWarnings("rawtypes")
        @Override
        public void addArgument(final Setter setter, Argument a) {
            Setter newSetter = setter;
            if (setter instanceof MethodSetter) {
                newSetter = new Setter() {

                    @SuppressWarnings("unchecked")
                    @Override
                    public void addValue(Object value) throws CmdLineException {
                        setter.addValue(value);
                    }

                    @Override
                    public Class getType() {
                        return setter.getType();
                    }

                    @Override
                    public boolean isMultiValued() {
                        return false;
                    }

                    @Override
                    public FieldSetter asFieldSetter() {
                        return setter.asFieldSetter();
                    }

                    @Override
                    public AnnotatedElement asAnnotatedElement() {
                        return setter.asAnnotatedElement();
                    }
                };
            }
            super.addArgument(newSetter, a);
        }
    };
}
Also used : CmdLineParser(org.kohsuke.args4j.CmdLineParser) Argument(org.kohsuke.args4j.Argument) MethodSetter(org.kohsuke.args4j.spi.MethodSetter) FieldSetter(org.kohsuke.args4j.spi.FieldSetter) MethodSetter(org.kohsuke.args4j.spi.MethodSetter) Setter(org.kohsuke.args4j.spi.Setter) FieldSetter(org.kohsuke.args4j.spi.FieldSetter) AnnotatedElement(java.lang.reflect.AnnotatedElement) CmdLineException(org.kohsuke.args4j.CmdLineException)

Aggregations

CmdLineException (org.kohsuke.args4j.CmdLineException)105 CmdLineParser (org.kohsuke.args4j.CmdLineParser)80 IOException (java.io.IOException)16 File (java.io.File)14 ArrayList (java.util.ArrayList)11 PrintStream (java.io.PrintStream)7 StringWriter (java.io.StringWriter)6 List (java.util.List)5 FileOutputStream (java.io.FileOutputStream)4 Path (java.nio.file.Path)4 CmdLineParser (com.google.gerrit.util.cli.CmdLineParser)3 FeatureExtractors (io.anserini.ltr.feature.FeatureExtractors)3 Qrels (io.anserini.util.Qrels)3 Directory (org.apache.lucene.store.Directory)3 FSDirectory (org.apache.lucene.store.FSDirectory)3 ConsoleReporter (com.codahale.metrics.ConsoleReporter)2 MetricRegistry (com.codahale.metrics.MetricRegistry)2 Project (com.google.gerrit.reviewdb.client.Project)2 OrmException (com.google.gwtorm.server.OrmException)2 Hudson (hudson.model.Hudson)2