Example usage for org.apache.commons.cli CommandLine getArgs

List of usage examples for org.apache.commons.cli CommandLine getArgs

Introduction

In this page you can find the example usage for org.apache.commons.cli CommandLine getArgs.

Prototype

public String[] getArgs() 

Source Link

Document

Retrieve any left-over non-recognized options and arguments

Usage

From source file:guru.nidi.ramlproxy.cli.ClientOptionsParser.java

private Command parseCommand(CommandLine cmd) throws ParseException {
    if (cmd.getArgs().length != 1) {
        throw new ParseException("No or multiple commands found: " + cmd.getArgList());
    }// w  w  w .ja  va 2  s . c  o  m
    final String commandStr = cmd.getArgs()[0].toLowerCase();
    final Command command = Command.byName(commandStr);
    if (command == null) {
        throw new ParseException("Unknown command '" + commandStr + "'");
    }
    return command;
}

From source file:net.sf.jvifm.control.RenameCommand.java

public RenameCommand(CommandLine cmdLine) {
    String[] args = cmdLine.getArgs();
    this.fromStr = args[0];
    this.toStr = args[1];
    this.dstDir = args[2];
}

From source file:com.aliyun.openservices.odps.console.commands.logview.GetStatusAction.java

public void configure(CommandLine cl) throws LogViewArgumentException {
    String[] args = cl.getArgs();
    if (args.length == 0) {
        throw new LogViewArgumentException("no instance id");
    } else if (args.length > 1) {
        throw new LogViewArgumentException("unexpected argument: " + args[1]);
    }/*from w ww  .  j  a v a  2  s .c o m*/
    ctx.setInstanceByName(args[0]);
}

From source file:alluxio.shell.command.UnmountCommand.java

@Override
public int run(CommandLine cl) throws AlluxioException, IOException {
    String[] args = cl.getArgs();
    AlluxioURI inputPath = new AlluxioURI(args[0]);

    mFileSystem.unmount(inputPath);//from w w  w .  ja v a 2 s  .c o m
    System.out.println("Unmounted " + inputPath);
    return 0;
}

From source file:alluxio.shell.command.TouchCommand.java

@Override
public int run(CommandLine cl) throws AlluxioException, IOException {
    String[] args = cl.getArgs();
    AlluxioURI inputPath = new AlluxioURI(args[0]);

    mFileSystem.createFile(inputPath, CreateFileOptions.defaults()).close();
    System.out.println(inputPath + " has been created");
    return 0;/*from w  ww  .  j  a va2  s  . co  m*/
}

From source file:alluxio.shell.command.UnsetTtlCommand.java

@Override
public int run(CommandLine cl) throws AlluxioException, IOException {
    String[] args = cl.getArgs();
    AlluxioURI inputPath = new AlluxioURI(args[0]);
    // Expiry doesn't matter in this case
    CommandUtils.setTtl(mFileSystem, inputPath, Constants.NO_TTL, TtlAction.DELETE);
    System.out.println("TTL of file '" + inputPath + "' was successfully removed.");
    return 0;//from w  w w.  j  a va2  s  .  c  om
}

From source file:android.example.hlsmerge.crypto.Main.java

private static CommandLine parseCommandLine(String[] args) {
    CommandLineParser parser = new PosixParser();
    CommandLine commandLine = null;

    Option help = new Option(OPT_HELP, "help", false, "print this message.");
    Option silent = new Option(OPT_SILENT, "silent", false, "silent mode.");
    Option overwrite = new Option(OPT_OVERWRITE, false, "overwrite output files.");

    Option key = OptionBuilder.withArgName(ARG_KEY).withLongOpt(OPT_KEY_LONG).hasArg()
            .withDescription("force use of the supplied AES-128 key.").create(OPT_KEY);

    Option outFile = OptionBuilder.withArgName(ARG_OUT_FILE).withLongOpt(OPT_OUT_FILE_LONG).hasArg()
            .withDescription("join all transport streams to one file.").create(OPT_OUT_FILE);

    Options options = new Options();

    options.addOption(help);/*  w w w .  j a v  a 2  s.co m*/
    options.addOption(silent);
    options.addOption(overwrite);
    options.addOption(key);
    options.addOption(outFile);

    try {
        commandLine = parser.parse(options, args);

        if (commandLine.hasOption(OPT_HELP) || (commandLine.getArgs().length < 1)) {
            new HelpFormatter().printHelp(CLI_SYNTAX, options);
            System.exit(0);
        }

        if (commandLine.hasOption(OPT_KEY)) {
            String optKey = commandLine.getOptionValue(OPT_KEY);

            if (!optKey.matches("[0-9a-fA-F]{32}")) {
                System.out.printf(
                        "Bad key format: \"%s\". Expected 32-character hex format.\nExample: -key 12ba7f70db4740dec4aab4c5c2c768d9",
                        optKey);
                System.exit(1);
            }
        }
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        new HelpFormatter().printHelp(CLI_SYNTAX, options);
        System.exit(1);
    }

    return commandLine;
}

From source file:alluxio.cli.fs.command.CatCommand.java

@Override
public int run(CommandLine cl) throws IOException {
    String[] args = cl.getArgs();
    runWildCardCmd(new AlluxioURI(args[0]), cl);

    return 0;/*from   w  w  w .  j a va  2s.co  m*/
}

From source file:alluxio.cli.fs.command.CopyToLocalCommand.java

@Override
public int run(CommandLine cl) throws AlluxioException, IOException {
    String[] args = cl.getArgs();
    String dst = args[1];/* ww  w  .ja v  a  2 s .  c  o m*/
    cl.getArgList().set(1, "file://" + new File(dst).getAbsolutePath());
    mCpCommand.run(cl);
    return 0;
}

From source file:alluxio.cli.fs.command.CopyFromLocalCommand.java

@Override
public int run(CommandLine cl) throws AlluxioException, IOException {
    String[] args = cl.getArgs();
    String srcPath = args[0];//  w w w. ja v a 2  s.c  om
    cl.getArgList().set(0, "file://" + new File(srcPath).getAbsolutePath());
    mCpCommand.run(cl);
    return 0;
}