Search in sources :

Example 1 with CmdBase

use of org.apache.bookkeeper.stream.cli.commands.CmdBase in project bookkeeper by apache.

the class StreamStorageCli method run.

boolean run(String[] args) {
    setupShell();
    if (args.length == 0) {
        commander.usage();
        return false;
    }
    int cmdPos;
    for (cmdPos = 0; cmdPos < args.length; cmdPos++) {
        if (commandMap.containsKey(args[cmdPos])) {
            break;
        }
    }
    try {
        commander.parse(Arrays.copyOfRange(args, 0, Math.min(cmdPos, args.length)));
    } catch (Exception e) {
        System.err.println(e.getMessage());
        System.err.println();
        commander.usage();
        return false;
    }
    if (shellArgs.help) {
        commander.usage();
        return false;
    }
    if (null == shellArgs.endpoint) {
        System.err.println("No endpoint is provided");
        commander.usage();
        return false;
    }
    Endpoint endpoint = NetUtils.parseEndpoint(shellArgs.endpoint);
    settingsBuilder.addEndpoints(endpoint);
    log.info("connecting to storage service = {}", endpoint);
    if (cmdPos == args.length) {
        commander.usage();
        return false;
    } else {
        String cmd = args[cmdPos];
        JCommander subCmd = commander.getCommands().get(cmd);
        CmdBase subCmdObj = (CmdBase) subCmd.getObjects().get(0);
        String[] subCmdArgs = Arrays.copyOfRange(args, cmdPos + 1, args.length);
        return subCmdObj.run(shellArgs.namespace, subCmdArgs);
    }
}
Also used : Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) JCommander(com.beust.jcommander.JCommander) CmdBase(org.apache.bookkeeper.stream.cli.commands.CmdBase) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint)

Aggregations

JCommander (com.beust.jcommander.JCommander)1 CmdBase (org.apache.bookkeeper.stream.cli.commands.CmdBase)1 Endpoint (org.apache.bookkeeper.stream.proto.common.Endpoint)1