Search in sources :

Example 1 with CommandLine

use of org.apache.commons.cli2.CommandLine in project jackrabbit-filevault by apache.

the class AbstractApplication method run.

protected void run(String[] args) {
    // setup and start
    init();
    Parser parser = new Parser();
    parser.setGroup(getApplicationCLGroup());
    parser.setHelpOption(optHelp);
    try {
        CommandLine cl = parser.parse(args);
        String logLevel = getEnv().getProperty(KEY_LOGLEVEL);
        if (cl.hasOption(optLogLevel)) {
            logLevel = (String) cl.getValue(optLogLevel);
        }
        if (logLevel != null) {
            LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
            // overwrite level of configuration file
            ch.qos.logback.classic.Logger rootLogger = context.getLogger(Logger.ROOT_LOGGER_NAME);
            rootLogger.setLevel(Level.toLevel(logLevel));
        }
        prepare(cl);
        execute(cl);
    } catch (OptionException e) {
        log.error("{}. Type --help for more information.", e.getMessage());
    } catch (ExecutionException e) {
        log.error("Error while starting: {}", e.getMessage());
    } finally {
        close();
    }
}
Also used : CommandLine(org.apache.commons.cli2.CommandLine) OptionException(org.apache.commons.cli2.OptionException) LoggerContext(ch.qos.logback.classic.LoggerContext) Parser(org.apache.commons.cli2.commandline.Parser)

Example 2 with CommandLine

use of org.apache.commons.cli2.CommandLine in project jackrabbit-filevault by apache.

the class ExecutionContext method execute.

public boolean execute(String[] args) {
    Parser parser = new Parser();
    parser.setHelpFormatter(getCmdHelpFormatter(null));
    parser.setGroup(getCommandsGroup());
    CommandLine cl = parser.parseAndHelp(args);
    return cl != null && execute(cl);
}
Also used : CommandLine(org.apache.commons.cli2.CommandLine) Parser(org.apache.commons.cli2.commandline.Parser)

Example 3 with CommandLine

use of org.apache.commons.cli2.CommandLine in project Practical-Machine-Learning by PacktPublishing.

the class InputDriver method main.

public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
    DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
    ArgumentBuilder abuilder = new ArgumentBuilder();
    GroupBuilder gbuilder = new GroupBuilder();
    Option inputOpt = DefaultOptionCreator.inputOption().withRequired(false).create();
    Option outputOpt = DefaultOptionCreator.outputOption().withRequired(false).create();
    Option vectorOpt = obuilder.withLongName("vector").withRequired(false).withArgument(abuilder.withName("v").withMinimum(1).withMaximum(1).create()).withDescription("The vector implementation to use.").withShortName("v").create();
    Option helpOpt = DefaultOptionCreator.helpOption();
    Group group = gbuilder.withName("Options").withOption(inputOpt).withOption(outputOpt).withOption(vectorOpt).withOption(helpOpt).create();
    try {
        Parser parser = new Parser();
        parser.setGroup(group);
        CommandLine cmdLine = parser.parse(args);
        if (cmdLine.hasOption(helpOpt)) {
            CommandLineUtil.printHelp(group);
            return;
        }
        Path input = new Path(cmdLine.getValue(inputOpt, "testdata").toString());
        Path output = new Path(cmdLine.getValue(outputOpt, "output").toString());
        String vectorClassName = cmdLine.getValue(vectorOpt, "org.apache.mahout.math.RandomAccessSparseVector").toString();
    // runJob(input, output, vectorClassName);
    } catch (OptionException e) {
        InputDriver.log.error("Exception parsing command line: ", e);
        CommandLineUtil.printHelp(group);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Group(org.apache.commons.cli2.Group) CommandLine(org.apache.commons.cli2.CommandLine) ArgumentBuilder(org.apache.commons.cli2.builder.ArgumentBuilder) GroupBuilder(org.apache.commons.cli2.builder.GroupBuilder) OptionException(org.apache.commons.cli2.OptionException) DefaultOptionBuilder(org.apache.commons.cli2.builder.DefaultOptionBuilder) Option(org.apache.commons.cli2.Option) Parser(org.apache.commons.cli2.commandline.Parser)

Example 4 with CommandLine

use of org.apache.commons.cli2.CommandLine in project jackrabbit-filevault by apache.

the class Test method main.

public static void main(String[] args) throws Exception {
    final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
    final ArgumentBuilder abuilder = new ArgumentBuilder();
    final CommandBuilder cbuilder = new CommandBuilder();
    final GroupBuilder gbuilder = new GroupBuilder();
    Option recursive = obuilder.withShortName("r").withLongName("recursive").withDescription("do recursively").create();
    Command update = cbuilder.withName("update").withName("up").withDescription("update the work directory").create();
    Option projecthelp = obuilder.withShortName("projecthelp").withShortName("p").withDescription("print project help information").create();
    Option version = obuilder.withShortName("v").withDescription("print the version information and exit").create();
    Group options = gbuilder.withName("Global options:").withOption(projecthelp).withOption(version).withMinimum(0).create();
    Option command = abuilder.withName("command").withMinimum(1).withMaximum(1).create();
    Option targets = abuilder.withName("arg").create();
    CliCommand exit = new org.apache.jackrabbit.vault.util.console.commands.CmdExit();
    CliCommand help = new org.apache.jackrabbit.vault.util.console.commands.CmdHelp();
    CliCommand setenv = new org.apache.jackrabbit.vault.util.console.commands.CmdSet();
    Group commands = gbuilder.withName("Commands:").withOption(help.getCommand()).withOption(exit.getCommand()).withOption(setenv.getCommand()).withOption(update).withMinimum(0).withMaximum(1).create();
    Group main = gbuilder.withName("").withOption(options).withOption(commands).withMinimum(0).create();
    HelpFormatter hf = new HelpFormatter();
    StringBuffer sep = new StringBuffer(hf.getPageWidth());
    while (sep.length() < hf.getPageWidth()) {
        sep.append("-");
    }
    hf.setHeader("File Vault version 1.0");
    hf.setDivider(sep.toString());
    hf.setShellCommand("vlt [options] <command> [arg1 [arg2 [arg3] ..]]");
    hf.setGroup(main);
    // hf.setHeader("bla bla version vla");
    // displayHelp();
    hf.getFullUsageSettings().removeAll(DisplaySetting.ALL);
    // hf.getDisplaySettings().add(DisplaySetting.DISPLAY_PARENT_ARGUMENT);
    // hf.getDisplaySettings().add(DisplaySetting.DISPLAY_PARENT_CHILDREN);
    // hf.getFullUsageSettings().remove(DisplaySetting.DISPLAY_OPTIONAL);
    hf.getFullUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
    hf.getFullUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_EXPANDED);
    hf.getDisplaySettings().remove(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
    hf.getDisplaySettings().remove(DisplaySetting.DISPLAY_PARENT_CHILDREN);
    hf.getDisplaySettings().add(DisplaySetting.DISPLAY_OPTIONAL);
    // hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PROPERTY_OPTION);
    // hf.getLineUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
    // hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_GROUP_NAME);
    // hf.getLineUsageSettings().remove(DisplaySetting.DISPLAY_PARENT_CHILDREN);
    // hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
    // hf.getLineUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_EXPANDED);
    // hf.getLineUsageSettings().remove(DisplaySetting.DISPLAY_PARENT_CHILDREN);
    // hf.getLineUsageSettings().remove(DisplaySetting.DISPLAY_PARENT_CHILDREN);
    hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PROPERTY_OPTION);
    hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PARENT_ARGUMENT);
    hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_ARGUMENT_BRACKETED);
    Parser parser = new Parser();
    parser.setHelpFormatter(hf);
    parser.setGroup(main);
    System.out.println(main);
    CommandLine cl = parser.parseAndHelp(args);
    if (cl != null) {
        if (exit.execute(null, cl)) {
            System.out.println("exit executed");
        } else if (help.execute(null, cl)) {
            System.out.println("help executed.");
        } else {
            hf.print();
        }
    }
}
Also used : Group(org.apache.commons.cli2.Group) GroupBuilder(org.apache.commons.cli2.builder.GroupBuilder) Parser(org.apache.commons.cli2.commandline.Parser) HelpFormatter(org.apache.commons.cli2.util.HelpFormatter) CommandLine(org.apache.commons.cli2.CommandLine) Command(org.apache.commons.cli2.option.Command) ArgumentBuilder(org.apache.commons.cli2.builder.ArgumentBuilder) DefaultOptionBuilder(org.apache.commons.cli2.builder.DefaultOptionBuilder) Option(org.apache.commons.cli2.Option) CommandBuilder(org.apache.commons.cli2.builder.CommandBuilder)

Example 5 with CommandLine

use of org.apache.commons.cli2.CommandLine in project jackrabbit-filevault by apache.

the class CmdSync method doExecute.

protected void doExecute(VaultFsApp app, CommandLine cl) throws Exception {
    Sync.Command cmd = (Sync.Command) cl.getValue(argCommand);
    if (cmd == null) {
        cmd = Sync.Command.INIT;
    }
    String root = (String) cl.getValue(optUri);
    RepositoryAddress addr = root == null ? null : new RepositoryAddress(root);
    String localPath = (String) cl.getValue(argLocalPath);
    File localFile = app.getPlatformFile(localPath == null ? "." : localPath, false).getCanonicalFile();
    VltContext vCtx = app.createVaultContext(localFile);
    vCtx.setVerbose(cl.hasOption(OPT_VERBOSE));
    vCtx.setQuiet(cl.hasOption(OPT_QUIET));
    Sync sc = new Sync(cmd, addr, localFile);
    sc.setForce(cl.hasOption(optForce));
    vCtx.execute(sc);
}
Also used : RepositoryAddress(org.apache.jackrabbit.vault.fs.api.RepositoryAddress) VltContext(org.apache.jackrabbit.vault.vlt.VltContext) Command(org.apache.commons.cli2.option.Command) Sync(org.apache.jackrabbit.vault.vlt.actions.Sync) File(java.io.File)

Aggregations

CommandLine (org.apache.commons.cli2.CommandLine)4 Parser (org.apache.commons.cli2.commandline.Parser)4 Group (org.apache.commons.cli2.Group)2 Option (org.apache.commons.cli2.Option)2 OptionException (org.apache.commons.cli2.OptionException)2 ArgumentBuilder (org.apache.commons.cli2.builder.ArgumentBuilder)2 DefaultOptionBuilder (org.apache.commons.cli2.builder.DefaultOptionBuilder)2 GroupBuilder (org.apache.commons.cli2.builder.GroupBuilder)2 Command (org.apache.commons.cli2.option.Command)2 LoggerContext (ch.qos.logback.classic.LoggerContext)1 File (java.io.File)1 CommandBuilder (org.apache.commons.cli2.builder.CommandBuilder)1 HelpFormatter (org.apache.commons.cli2.util.HelpFormatter)1 Path (org.apache.hadoop.fs.Path)1 RepositoryAddress (org.apache.jackrabbit.vault.fs.api.RepositoryAddress)1 VltContext (org.apache.jackrabbit.vault.vlt.VltContext)1 Sync (org.apache.jackrabbit.vault.vlt.actions.Sync)1