Example usage for org.apache.commons.cli Option getOpt

List of usage examples for org.apache.commons.cli Option getOpt

Introduction

In this page you can find the example usage for org.apache.commons.cli Option getOpt.

Prototype

public String getOpt() 

Source Link

Document

Retrieve the name of this Option.

Usage

From source file:org.apache.cassandra.staleness.Staleness.java

/**
 * Printing out help message/*from   w w w.  ja v a  2s  . c o  m*/
 */
public static void printHelpMessage() {
    System.out.println("Usage: ./bin/cassandra-staleness [options]\n\nOptions:");

    for (Object o : Session.availableOptions.getOptions()) {
        Option option = (Option) o;
        String upperCaseName = option.getLongOpt().toUpperCase();
        System.out.println(String.format("-%s%s, --%s%s%n\t\t%s%n", option.getOpt(),
                (option.hasArg()) ? " " + upperCaseName : "", option.getLongOpt(),
                (option.hasArg()) ? "=" + upperCaseName : "", option.getDescription()));
    }
}

From source file:org.apache.cassandra.stress.settings.Legacy.java

public static void printHelpMessage() {
    System.out.println("Usage: ./bin/cassandra-stress legacy [options]\n\nOptions:");
    System.out.println("THIS IS A LEGACY SUPPORT MODE");

    for (Object o : availableOptions.getOptions()) {
        Option option = (Option) o;
        String upperCaseName = option.getLongOpt().toUpperCase();
        System.out.println(String.format("-%s%s, --%s%s%n\t\t%s%n", option.getOpt(),
                (option.hasArg()) ? " " + upperCaseName : "", option.getLongOpt(),
                (option.hasArg()) ? "=" + upperCaseName : "", option.getDescription()));
    }//from   w w  w  . j  a v  a 2s. c  o  m
}

From source file:org.apache.commons.jci.examples.commandline.CommandlineCompiler.java

public static void main(String[] args) throws Exception {

    final Options options = new Options();

    options.addOption(OptionBuilder.withArgName("a.jar:b.jar").hasArg().withValueSeparator(':')
            .withDescription("Specify where to find user class files").create("classpath"));

    options.addOption(OptionBuilder.withArgName("release").hasArg()
            .withDescription("Provide source compatibility with specified release").create("source"));

    options.addOption(OptionBuilder.withArgName("release").hasArg()
            .withDescription("Generate class files for specific VM version").create("target"));

    options.addOption(OptionBuilder.withArgName("path").hasArg()
            .withDescription("Specify where to find input source files").create("sourcepath"));

    options.addOption(OptionBuilder.withArgName("directory").hasArg()
            .withDescription("Specify where to place generated class files").create("d"));

    options.addOption(OptionBuilder.withArgName("num").hasArg()
            .withDescription("Stop compilation after these number of errors").create("Xmaxerrs"));

    options.addOption(OptionBuilder.withArgName("num").hasArg()
            .withDescription("Stop compilation after these number of warning").create("Xmaxwarns"));

    options.addOption(OptionBuilder.withDescription("Generate no warnings").create("nowarn"));

    //        final HelpFormatter formatter = new HelpFormatter();
    //        formatter.printHelp("jci", options);

    final CommandLineParser parser = new GnuParser();
    final CommandLine cmd = parser.parse(options, args, true);

    ClassLoader classloader = CommandlineCompiler.class.getClassLoader();
    File sourcepath = new File(".");
    File targetpath = new File(".");
    int maxerrs = 10;
    int maxwarns = 10;
    final boolean nowarn = cmd.hasOption("nowarn");

    final JavaCompiler compiler = new JavaCompilerFactory().createCompiler("eclipse");
    final JavaCompilerSettings settings = compiler.createDefaultSettings();

    for (Iterator it = cmd.iterator(); it.hasNext();) {
        final Option option = (Option) it.next();
        if ("classpath".equals(option.getOpt())) {
            final String[] values = option.getValues();
            final URL[] urls = new URL[values.length];
            for (int i = 0; i < urls.length; i++) {
                urls[i] = new File(values[i]).toURL();
            }/*from   ww  w.ja  v  a2s  . c  om*/
            classloader = new URLClassLoader(urls);
        } else if ("source".equals(option.getOpt())) {
            settings.setSourceVersion(option.getValue());
        } else if ("target".equals(option.getOpt())) {
            settings.setTargetVersion(option.getValue());
        } else if ("sourcepath".equals(option.getOpt())) {
            sourcepath = new File(option.getValue());
        } else if ("d".equals(option.getOpt())) {
            targetpath = new File(option.getValue());
        } else if ("Xmaxerrs".equals(option.getOpt())) {
            maxerrs = Integer.parseInt(option.getValue());
        } else if ("Xmaxwarns".equals(option.getOpt())) {
            maxwarns = Integer.parseInt(option.getValue());
        }
    }

    final ResourceReader reader = new FileResourceReader(sourcepath);
    final ResourceStore store = new FileResourceStore(targetpath);

    final int maxErrors = maxerrs;
    final int maxWarnings = maxwarns;
    compiler.setCompilationProblemHandler(new CompilationProblemHandler() {
        int errors = 0;
        int warnings = 0;

        public boolean handle(final CompilationProblem pProblem) {

            if (pProblem.isError()) {
                System.err.println(pProblem);

                errors++;

                if (errors >= maxErrors) {
                    return false;
                }
            } else {
                if (!nowarn) {
                    System.err.println(pProblem);
                }

                warnings++;

                if (warnings >= maxWarnings) {
                    return false;
                }
            }

            return true;
        }
    });

    final String[] resource = cmd.getArgs();

    for (int i = 0; i < resource.length; i++) {
        System.out.println("compiling " + resource[i]);
    }

    final CompilationResult result = compiler.compile(resource, reader, store, classloader);

    System.out.println(result.getErrors().length + " errors");
    System.out.println(result.getWarnings().length + " warnings");

}

From source file:org.apache.falcon.cli.FalconAdminCLI.java

public int adminCommand(CommandLine commandLine, FalconClient client, String falconUrl)
        throws FalconCLIException, IOException {
    String result;/*from www  . j  a v a  2s.  co  m*/
    Set<String> optionsList = new HashSet<String>();
    for (Option option : commandLine.getOptions()) {
        optionsList.add(option.getOpt());
    }

    String doAsUser = commandLine.getOptionValue(DO_AS_OPT);

    if (optionsList.contains(STACK_OPTION)) {
        result = client.getThreadDump(doAsUser);
        OUT.get().println(result);
    }

    int exitValue = 0;
    if (optionsList.contains(STATUS_OPT)) {
        try {
            int status = client.getStatus(doAsUser);
            if (status != 200) {
                ERR.get().println("Falcon server is not fully operational (on " + falconUrl + "). "
                        + "Please check log files.");
                exitValue = status;
            } else {
                OUT.get().println("Falcon server is running (on " + falconUrl + ")");
            }
        } catch (Exception e) {
            ERR.get().println("Falcon server doesn't seem to be running on " + falconUrl);
            exitValue = -1;
        }
    } else if (optionsList.contains(VERSION_OPT)) {
        result = client.getVersion(doAsUser);
        OUT.get().println("Falcon server build version: " + result);
    } else if (optionsList.contains(HELP_CMD)) {
        OUT.get().println("Falcon Help");
    }
    return exitValue;
}

From source file:org.apache.falcon.cli.FalconCLI.java

private void instanceCommand(CommandLine commandLine, FalconClient client)
        throws FalconCLIException, IOException {
    Set<String> optionsList = new HashSet<String>();
    for (Option option : commandLine.getOptions()) {
        optionsList.add(option.getOpt());
    }//from   w  w w  .  ja v a  2s . c o  m

    String result;
    String type = commandLine.getOptionValue(ENTITY_TYPE_OPT);
    String entity = commandLine.getOptionValue(ENTITY_NAME_OPT);
    String instanceTime = commandLine.getOptionValue(INSTANCE_TIME_OPT);
    String start = commandLine.getOptionValue(START_OPT);
    String end = commandLine.getOptionValue(END_OPT);
    String filePath = commandLine.getOptionValue(FILE_PATH_OPT);
    String runId = commandLine.getOptionValue(RUNID_OPT);
    String colo = commandLine.getOptionValue(COLO_OPT);
    String clusters = commandLine.getOptionValue(CLUSTERS_OPT);
    String sourceClusters = commandLine.getOptionValue(SOURCECLUSTER_OPT);
    List<LifeCycle> lifeCycles = getLifeCycle(commandLine.getOptionValue(LIFECYCLE_OPT));
    String filterBy = commandLine.getOptionValue(FILTER_BY_OPT);
    String orderBy = commandLine.getOptionValue(ORDER_BY_OPT);
    String sortOrder = commandLine.getOptionValue(SORT_ORDER_OPT);
    String doAsUser = commandLine.getOptionValue(DO_AS_OPT);
    Integer offset = parseIntegerInput(commandLine.getOptionValue(OFFSET_OPT), 0, "offset");
    Integer numResults = parseIntegerInput(commandLine.getOptionValue(NUM_RESULTS_OPT), null, "numResults");

    colo = getColo(colo);
    String instanceAction = "instance";
    validateSortOrder(sortOrder);
    validateInstanceCommands(optionsList, entity, type, colo);

    if (optionsList.contains(TRIAGE_OPT)) {
        validateNotEmpty(colo, COLO_OPT);
        validateNotEmpty(start, START_OPT);
        validateNotEmpty(type, ENTITY_TYPE_OPT);
        validateEntityTypeForSummary(type);
        validateNotEmpty(entity, ENTITY_NAME_OPT);
        result = client.triage(type, entity, start, colo).toString();
    } else if (optionsList.contains(DEPENDENCY_OPT)) {
        validateNotEmpty(instanceTime, INSTANCE_TIME_OPT);
        InstanceDependencyResult response = client.getInstanceDependencies(type, entity, instanceTime, colo);
        result = ResponseHelper.getString(response);

    } else if (optionsList.contains(RUNNING_OPT)) {
        validateOrderBy(orderBy, instanceAction);
        validateFilterBy(filterBy, instanceAction);
        result = ResponseHelper.getString(client.getRunningInstances(type, entity, colo, lifeCycles, filterBy,
                orderBy, sortOrder, offset, numResults, doAsUser));
    } else if (optionsList.contains(STATUS_OPT) || optionsList.contains(LIST_OPT)) {
        validateOrderBy(orderBy, instanceAction);
        validateFilterBy(filterBy, instanceAction);
        result = ResponseHelper.getString(client.getStatusOfInstances(type, entity, start, end, colo,
                lifeCycles, filterBy, orderBy, sortOrder, offset, numResults, doAsUser));
    } else if (optionsList.contains(SUMMARY_OPT)) {
        validateOrderBy(orderBy, "summary");
        validateFilterBy(filterBy, "summary");
        result = ResponseHelper.getString(client.getSummaryOfInstances(type, entity, start, end, colo,
                lifeCycles, filterBy, orderBy, sortOrder, doAsUser));
    } else if (optionsList.contains(KILL_OPT)) {
        validateNotEmpty(start, START_OPT);
        validateNotEmpty(end, END_OPT);
        result = ResponseHelper.getString(client.killInstances(type, entity, start, end, colo, clusters,
                sourceClusters, lifeCycles, doAsUser));
    } else if (optionsList.contains(SUSPEND_OPT)) {
        validateNotEmpty(start, START_OPT);
        validateNotEmpty(end, END_OPT);
        result = ResponseHelper.getString(client.suspendInstances(type, entity, start, end, colo, clusters,
                sourceClusters, lifeCycles, doAsUser));
    } else if (optionsList.contains(RESUME_OPT)) {
        validateNotEmpty(start, START_OPT);
        validateNotEmpty(end, END_OPT);
        result = ResponseHelper.getString(client.resumeInstances(type, entity, start, end, colo, clusters,
                sourceClusters, lifeCycles, doAsUser));
    } else if (optionsList.contains(RERUN_OPT)) {
        validateNotEmpty(start, START_OPT);
        validateNotEmpty(end, END_OPT);
        boolean isForced = false;
        if (optionsList.contains(FORCE_RERUN_FLAG)) {
            isForced = true;
        }
        result = ResponseHelper.getString(client.rerunInstances(type, entity, start, end, filePath, colo,
                clusters, sourceClusters, lifeCycles, isForced, doAsUser));
    } else if (optionsList.contains(LOG_OPT)) {
        validateOrderBy(orderBy, instanceAction);
        validateFilterBy(filterBy, instanceAction);
        result = ResponseHelper.getString(client.getLogsOfInstances(type, entity, start, end, colo, runId,
                lifeCycles, filterBy, orderBy, sortOrder, offset, numResults, doAsUser), runId);
    } else if (optionsList.contains(PARARMS_OPT)) {
        // start time is the nominal time of instance
        result = ResponseHelper
                .getString(client.getParamsOfInstance(type, entity, start, colo, lifeCycles, doAsUser));
    } else if (optionsList.contains(LISTING_OPT)) {
        result = ResponseHelper.getString(client.getFeedListing(type, entity, start, end, colo, doAsUser));
    } else {
        throw new FalconCLIException("Invalid command");
    }

    OUT.get().println(result);
}

From source file:org.apache.falcon.cli.FalconCLI.java

private void entityCommand(CommandLine commandLine, FalconClient client)
        throws FalconCLIException, IOException {
    Set<String> optionsList = new HashSet<String>();
    for (Option option : commandLine.getOptions()) {
        optionsList.add(option.getOpt());
    }/*from   w w w .j ava 2 s .  c om*/

    String result = null;
    String entityType = commandLine.getOptionValue(ENTITY_TYPE_OPT);
    String entityName = commandLine.getOptionValue(ENTITY_NAME_OPT);
    String filePath = commandLine.getOptionValue(FILE_PATH_OPT);
    String colo = commandLine.getOptionValue(COLO_OPT);
    String cluster = commandLine.getOptionValue(CLUSTER_OPT);
    String start = commandLine.getOptionValue(START_OPT);
    String end = commandLine.getOptionValue(END_OPT);
    String orderBy = commandLine.getOptionValue(ORDER_BY_OPT);
    String sortOrder = commandLine.getOptionValue(SORT_ORDER_OPT);
    String filterBy = commandLine.getOptionValue(FILTER_BY_OPT);
    String filterTags = commandLine.getOptionValue(TAGS_OPT);
    String nameSubsequence = commandLine.getOptionValue(NAMESEQ_OPT);
    String tagKeywords = commandLine.getOptionValue(TAGKEYS_OPT);
    String fields = commandLine.getOptionValue(FIELDS_OPT);
    String feedInstancePath = commandLine.getOptionValue(PATH_OPT);
    Integer offset = parseIntegerInput(commandLine.getOptionValue(OFFSET_OPT), 0, "offset");
    Integer numResults = parseIntegerInput(commandLine.getOptionValue(NUM_RESULTS_OPT), null, "numResults");
    String doAsUser = commandLine.getOptionValue(DO_AS_OPT);

    Integer numInstances = parseIntegerInput(commandLine.getOptionValue(NUM_INSTANCES_OPT), 7, "numInstances");
    Boolean skipDryRun = null;
    if (optionsList.contains(SKIPDRYRUN_OPT)) {
        skipDryRun = true;
    }

    EntityType entityTypeEnum = null;
    if (optionsList.contains(LIST_OPT)) {
        if (entityType == null) {
            entityType = "";
        }
        if (StringUtils.isNotEmpty(entityType)) {
            String[] types = entityType.split(",");
            for (String type : types) {
                EntityType.getEnum(type);
            }
        }
    } else {
        validateNotEmpty(entityType, ENTITY_TYPE_OPT);
        entityTypeEnum = EntityType.getEnum(entityType);
    }
    validateSortOrder(sortOrder);
    String entityAction = "entity";

    if (optionsList.contains(SUBMIT_OPT)) {
        validateNotEmpty(filePath, "file");
        validateColo(optionsList);
        result = client.submit(entityType, filePath, doAsUser).getMessage();
    } else if (optionsList.contains(LOOKUP_OPT)) {
        validateNotEmpty(feedInstancePath, PATH_OPT);
        FeedLookupResult resp = client.reverseLookUp(entityType, feedInstancePath, doAsUser);
        result = ResponseHelper.getString(resp);

    } else if (optionsList.contains(UPDATE_OPT)) {
        validateNotEmpty(filePath, "file");
        validateColo(optionsList);
        validateNotEmpty(entityName, ENTITY_NAME_OPT);
        result = client.update(entityType, entityName, filePath, skipDryRun, doAsUser).getMessage();
    } else if (optionsList.contains(SUBMIT_AND_SCHEDULE_OPT)) {
        validateNotEmpty(filePath, "file");
        validateColo(optionsList);
        result = client.submitAndSchedule(entityType, filePath, skipDryRun, doAsUser).getMessage();
    } else if (optionsList.contains(VALIDATE_OPT)) {
        validateNotEmpty(filePath, "file");
        validateColo(optionsList);
        result = client.validate(entityType, filePath, skipDryRun, doAsUser).getMessage();
    } else if (optionsList.contains(SCHEDULE_OPT)) {
        validateNotEmpty(entityName, ENTITY_NAME_OPT);
        colo = getColo(colo);
        result = client.schedule(entityTypeEnum, entityName, colo, skipDryRun, doAsUser).getMessage();
    } else if (optionsList.contains(SUSPEND_OPT)) {
        validateNotEmpty(entityName, ENTITY_NAME_OPT);
        colo = getColo(colo);
        result = client.suspend(entityTypeEnum, entityName, colo, doAsUser).getMessage();
    } else if (optionsList.contains(RESUME_OPT)) {
        validateNotEmpty(entityName, ENTITY_NAME_OPT);
        colo = getColo(colo);
        result = client.resume(entityTypeEnum, entityName, colo, doAsUser).getMessage();
    } else if (optionsList.contains(DELETE_OPT)) {
        validateColo(optionsList);
        validateNotEmpty(entityName, ENTITY_NAME_OPT);
        result = client.delete(entityTypeEnum, entityName, doAsUser).getMessage();
    } else if (optionsList.contains(STATUS_OPT)) {
        validateNotEmpty(entityName, ENTITY_NAME_OPT);
        colo = getColo(colo);
        result = client.getStatus(entityTypeEnum, entityName, colo, doAsUser).getMessage();
    } else if (optionsList.contains(DEFINITION_OPT)) {
        validateColo(optionsList);
        validateNotEmpty(entityName, ENTITY_NAME_OPT);
        result = client.getDefinition(entityType, entityName, doAsUser).toString();
    } else if (optionsList.contains(DEPENDENCY_OPT)) {
        validateColo(optionsList);
        validateNotEmpty(entityName, ENTITY_NAME_OPT);
        result = client.getDependency(entityType, entityName, doAsUser).toString();
    } else if (optionsList.contains(LIST_OPT)) {
        validateColo(optionsList);
        validateEntityFields(fields);
        validateOrderBy(orderBy, entityAction);
        validateFilterBy(filterBy, entityAction);
        EntityList entityList = client.getEntityList(entityType, fields, nameSubsequence, tagKeywords, filterBy,
                filterTags, orderBy, sortOrder, offset, numResults, doAsUser);
        result = entityList != null ? entityList.toString() : "No entity of type (" + entityType + ") found.";
    } else if (optionsList.contains(SUMMARY_OPT)) {
        validateEntityTypeForSummary(entityType);
        validateNotEmpty(cluster, CLUSTER_OPT);
        validateEntityFields(fields);
        validateFilterBy(filterBy, entityAction);
        validateOrderBy(orderBy, entityAction);
        result = ResponseHelper.getString(client.getEntitySummary(entityType, cluster, start, end, fields,
                filterBy, filterTags, orderBy, sortOrder, offset, numResults, numInstances, doAsUser));
    } else if (optionsList.contains(TOUCH_OPT)) {
        validateNotEmpty(entityName, ENTITY_NAME_OPT);
        colo = getColo(colo);
        result = client.touch(entityType, entityName, colo, skipDryRun, doAsUser).getMessage();
    } else if (optionsList.contains(HELP_CMD)) {
        OUT.get().println("Falcon Help");
    } else {
        throw new FalconCLIException("Invalid command");
    }
    OUT.get().println(result);
}

From source file:org.apache.falcon.cli.FalconCLI.java

private int adminCommand(CommandLine commandLine, FalconClient client, String falconUrl)
        throws FalconCLIException, IOException {
    String result;//from   w ww  . j  a  va  2  s  .com
    Set<String> optionsList = new HashSet<String>();
    for (Option option : commandLine.getOptions()) {
        optionsList.add(option.getOpt());
    }

    String doAsUser = commandLine.getOptionValue(DO_AS_OPT);

    if (optionsList.contains(STACK_OPTION)) {
        result = client.getThreadDump(doAsUser);
        OUT.get().println(result);
    }
    int exitValue = 0;
    if (optionsList.contains(STATUS_OPTION)) {
        try {
            int status = client.getStatus(doAsUser);
            if (status != 200) {
                ERR.get().println("Falcon server is not fully operational (on " + falconUrl + "). "
                        + "Please check log files.");
                exitValue = status;
            } else {
                OUT.get().println("Falcon server is running (on " + falconUrl + ")");
            }
        } catch (Exception e) {
            ERR.get().println("Falcon server doesn't seem to be running on " + falconUrl);
            exitValue = -1;
        }
    } else if (optionsList.contains(VERSION_OPTION)) {
        result = client.getVersion(doAsUser);
        OUT.get().println("Falcon server build version: " + result);
    } else if (optionsList.contains(HELP_CMD)) {
        OUT.get().println("Falcon Help");
    }

    return exitValue;
}

From source file:org.apache.falcon.cli.FalconCLI.java

private void recipeCommand(CommandLine commandLine, FalconClient client) throws FalconCLIException {
    Set<String> optionsList = new HashSet<String>();
    for (Option option : commandLine.getOptions()) {
        optionsList.add(option.getOpt());
    }//from  ww w .  j ava  2 s . com

    String recipeName = commandLine.getOptionValue(RECIPE_NAME);
    String recipeToolClass = commandLine.getOptionValue(RECIPE_TOOL_CLASS_NAME);
    String recipeOperation = commandLine.getOptionValue(RECIPE_OPERATION);
    String doAsUser = commandLine.getOptionValue(DO_AS_OPT);

    validateNotEmpty(recipeName, RECIPE_NAME);
    validateNotEmpty(recipeOperation, RECIPE_OPERATION);
    validateRecipeOperations(recipeOperation);
    Boolean skipDryRun = null;
    if (optionsList.contains(SKIPDRYRUN_OPT)) {
        skipDryRun = true;
    }

    String result = client.submitRecipe(recipeName, recipeToolClass, recipeOperation, skipDryRun, doAsUser)
            .toString();
    OUT.get().println(result);
}

From source file:org.apache.falcon.cli.FalconEntityCLI.java

public void entityCommand(CommandLine commandLine, FalconClient client) throws FalconCLIException, IOException {
    Set<String> optionsList = new HashSet<String>();
    for (Option option : commandLine.getOptions()) {
        optionsList.add(option.getOpt());
    }/*from w w  w  .  j  a  v  a2 s  .c om*/

    String result = null;
    String entityType = commandLine.getOptionValue(TYPE_OPT);
    String entityName = commandLine.getOptionValue(ENTITY_NAME_OPT);
    String filePath = commandLine.getOptionValue(FILE_PATH_OPT);
    String colo = commandLine.getOptionValue(COLO_OPT);
    colo = getColo(colo);
    String cluster = commandLine.getOptionValue(CLUSTER_OPT);
    String start = commandLine.getOptionValue(START_OPT);
    String end = commandLine.getOptionValue(END_OPT);
    String orderBy = commandLine.getOptionValue(ORDER_BY_OPT);
    String sortOrder = commandLine.getOptionValue(SORT_ORDER_OPT);
    String filterBy = commandLine.getOptionValue(FILTER_BY_OPT);
    String filterTags = commandLine.getOptionValue(TAGS_OPT);
    String nameSubsequence = commandLine.getOptionValue(NAMESEQ_OPT);
    String tagKeywords = commandLine.getOptionValue(TAGKEYS_OPT);
    String fields = commandLine.getOptionValue(FIELDS_OPT);
    String feedInstancePath = commandLine.getOptionValue(PATH_OPT);
    Integer offset = parseIntegerInput(commandLine.getOptionValue(OFFSET_OPT), 0, "offset");
    Integer numResults = parseIntegerInput(commandLine.getOptionValue(NUM_RESULTS_OPT), null, "numResults");
    String doAsUser = commandLine.getOptionValue(DO_AS_OPT);

    Integer numInstances = parseIntegerInput(commandLine.getOptionValue(NUM_INSTANCES_OPT), 7, "numInstances");
    Boolean skipDryRun = null;
    if (optionsList.contains(SKIPDRYRUN_OPT)) {
        skipDryRun = true;
    }

    String userProps = commandLine.getOptionValue(PROPS_OPT);

    EntityType entityTypeEnum = null;
    if (optionsList.contains(LIST_OPT)) {
        if (entityType == null) {
            entityType = "";
        }
        if (StringUtils.isNotEmpty(entityType)) {
            String[] types = entityType.split(",");
            for (String type : types) {
                EntityType.getEnum(type);
            }
        }
    } else {
        validateNotEmpty(entityType, TYPE_OPT);
        entityTypeEnum = EntityType.getEnum(entityType);
    }
    validateSortOrder(sortOrder);
    String entityAction = "entity";

    if (optionsList.contains(SLA_MISS_ALERT_OPT)) {
        validateNotEmpty(entityType, TYPE_OPT);
        validateNotEmpty(start, START_OPT);
        parseDateString(start);
        parseDateString(end);
        SchedulableEntityInstanceResult response = client.getFeedSlaMissPendingAlerts(entityType, entityName,
                start, end, colo);
        result = ResponseHelper.getString(response);
    } else if (optionsList.contains(SUBMIT_OPT)) {
        validateNotEmpty(filePath, "file");
        validateColo(optionsList);
        result = client.submit(entityType, filePath, doAsUser).getMessage();
    } else if (optionsList.contains(LOOKUP_OPT)) {
        validateNotEmpty(feedInstancePath, PATH_OPT);
        FeedLookupResult resp = client.reverseLookUp(entityType, feedInstancePath, doAsUser);
        result = ResponseHelper.getString(resp);
    } else if (optionsList.contains(UPDATE_OPT)) {
        validateNotEmpty(filePath, "file");
        validateColo(optionsList);
        validateNotEmpty(entityName, ENTITY_NAME_OPT);
        result = client.update(entityType, entityName, filePath, skipDryRun, doAsUser).getMessage();
    } else if (optionsList.contains(SUBMIT_AND_SCHEDULE_OPT)) {
        validateNotEmpty(filePath, "file");
        validateColo(optionsList);
        result = client.submitAndSchedule(entityType, filePath, skipDryRun, doAsUser, userProps).getMessage();
    } else if (optionsList.contains(VALIDATE_OPT)) {
        validateNotEmpty(filePath, "file");
        validateColo(optionsList);
        result = client.validate(entityType, filePath, skipDryRun, doAsUser).getMessage();
    } else if (optionsList.contains(SCHEDULE_OPT)) {
        validateNotEmpty(entityName, ENTITY_NAME_OPT);
        colo = getColo(colo);
        result = client.schedule(entityTypeEnum, entityName, colo, skipDryRun, doAsUser, userProps)
                .getMessage();
    } else if (optionsList.contains(SUSPEND_OPT)) {
        validateNotEmpty(entityName, ENTITY_NAME_OPT);
        colo = getColo(colo);
        result = client.suspend(entityTypeEnum, entityName, colo, doAsUser).getMessage();
    } else if (optionsList.contains(RESUME_OPT)) {
        validateNotEmpty(entityName, ENTITY_NAME_OPT);
        colo = getColo(colo);
        result = client.resume(entityTypeEnum, entityName, colo, doAsUser).getMessage();
    } else if (optionsList.contains(DELETE_OPT)) {
        validateColo(optionsList);
        validateNotEmpty(entityName, ENTITY_NAME_OPT);
        result = client.delete(entityTypeEnum, entityName, doAsUser).getMessage();
    } else if (optionsList.contains(STATUS_OPT)) {
        validateNotEmpty(entityName, ENTITY_NAME_OPT);
        colo = getColo(colo);
        result = client.getStatus(entityTypeEnum, entityName, colo, doAsUser).getMessage();
    } else if (optionsList.contains(DEFINITION_OPT)) {
        validateColo(optionsList);
        validateNotEmpty(entityName, ENTITY_NAME_OPT);
        result = client.getDefinition(entityType, entityName, doAsUser).toString();
    } else if (optionsList.contains(DEPENDENCY_OPT)) {
        validateColo(optionsList);
        validateNotEmpty(entityName, ENTITY_NAME_OPT);
        result = client.getDependency(entityType, entityName, doAsUser).toString();
    } else if (optionsList.contains(LIST_OPT)) {
        validateColo(optionsList);
        validateEntityFields(fields);
        validateOrderBy(orderBy, entityAction);
        validateFilterBy(filterBy, entityAction);
        EntityList entityList = client.getEntityList(entityType, fields, nameSubsequence, tagKeywords, filterBy,
                filterTags, orderBy, sortOrder, offset, numResults, doAsUser);
        result = entityList != null ? entityList.toString() : "No entity of type (" + entityType + ") found.";
    } else if (optionsList.contains(SUMMARY_OPT)) {
        validateEntityTypeForSummary(entityType);
        validateNotEmpty(cluster, CLUSTER_OPT);
        validateEntityFields(fields);
        validateFilterBy(filterBy, entityAction);
        validateOrderBy(orderBy, entityAction);
        result = ResponseHelper.getString(client.getEntitySummary(entityType, cluster, start, end, fields,
                filterBy, filterTags, orderBy, sortOrder, offset, numResults, numInstances, doAsUser));
    } else if (optionsList.contains(TOUCH_OPT)) {
        validateNotEmpty(entityName, ENTITY_NAME_OPT);
        colo = getColo(colo);
        result = client.touch(entityType, entityName, colo, skipDryRun, doAsUser).getMessage();
    } else if (optionsList.contains(HELP_CMD)) {
        OUT.get().println("Falcon Help");
    } else {
        throw new FalconCLIException("Invalid command");
    }
    OUT.get().println(result);
}

From source file:org.apache.falcon.cli.FalconExtensionCLI.java

public void extensionCommand(CommandLine commandLine, FalconClient client) throws FalconCLIException {
    Set<String> optionsList = new HashSet<>();
    for (Option option : commandLine.getOptions()) {
        optionsList.add(option.getOpt());
    }/*  w w w .  j a  v  a  2s  .  c om*/

    String result;
    String extensionName = commandLine.getOptionValue(ENTENSION_NAME_OPT);
    String jobName = commandLine.getOptionValue(JOB_NAME_OPT);
    String filePath = commandLine.getOptionValue(FalconCLIConstants.FILE_PATH_OPT);
    String doAsUser = commandLine.getOptionValue(FalconCLIConstants.DO_AS_OPT);

    if (optionsList.contains(ENUMERATE_OPT)) {
        result = client.enumerateExtensions();
        result = prettyPrintJson(result);
    } else if (optionsList.contains(DEFINITION_OPT)) {
        validateRequiredParameter(extensionName, ENTENSION_NAME_OPT);
        result = client.getExtensionDefinition(extensionName);
        result = prettyPrintJson(result);
    } else if (optionsList.contains(DESCRIBE_OPT)) {
        validateRequiredParameter(extensionName, ENTENSION_NAME_OPT);
        result = client.getExtensionDescription(extensionName);
    } else if (optionsList.contains(FalconCLIConstants.SUBMIT_OPT)) {
        validateRequiredParameter(extensionName, ENTENSION_NAME_OPT);
        validateRequiredParameter(filePath, FalconCLIConstants.FILE_PATH_OPT);
        result = client.submitExtensionJob(extensionName, filePath, doAsUser).getMessage();
    } else if (optionsList.contains(FalconCLIConstants.SUBMIT_AND_SCHEDULE_OPT)) {
        validateRequiredParameter(extensionName, ENTENSION_NAME_OPT);
        validateRequiredParameter(filePath, FalconCLIConstants.FILE_PATH_OPT);
        result = client.submitAndScheduleExtensionJob(extensionName, filePath, doAsUser).getMessage();
    } else if (optionsList.contains(FalconCLIConstants.UPDATE_OPT)) {
        validateRequiredParameter(extensionName, ENTENSION_NAME_OPT);
        validateRequiredParameter(filePath, FalconCLIConstants.FILE_PATH_OPT);
        result = client.updateExtensionJob(extensionName, filePath, doAsUser).getMessage();
    } else if (optionsList.contains(FalconCLIConstants.VALIDATE_OPT)) {
        validateRequiredParameter(extensionName, ENTENSION_NAME_OPT);
        validateRequiredParameter(filePath, FalconCLIConstants.FILE_PATH_OPT);
        result = client.validateExtensionJob(extensionName, filePath, doAsUser).getMessage();
    } else if (optionsList.contains(FalconCLIConstants.SCHEDULE_OPT)) {
        validateRequiredParameter(jobName, JOB_NAME_OPT);
        result = client.scheduleExtensionJob(jobName, doAsUser).getMessage();
    } else if (optionsList.contains(FalconCLIConstants.SUSPEND_OPT)) {
        validateRequiredParameter(jobName, JOB_NAME_OPT);
        result = client.suspendExtensionJob(jobName, doAsUser).getMessage();
    } else if (optionsList.contains(FalconCLIConstants.RESUME_OPT)) {
        validateRequiredParameter(jobName, JOB_NAME_OPT);
        result = client.resumeExtensionJob(jobName, doAsUser).getMessage();
    } else if (optionsList.contains(FalconCLIConstants.DELETE_OPT)) {
        validateRequiredParameter(jobName, JOB_NAME_OPT);
        result = client.deleteExtensionJob(jobName, doAsUser).getMessage();
    } else if (optionsList.contains(FalconCLIConstants.LIST_OPT)) {
        validateRequiredParameter(extensionName, ENTENSION_NAME_OPT);
        ExtensionJobList jobs = client.listExtensionJob(extensionName, doAsUser,
                commandLine.getOptionValue(FalconCLIConstants.SORT_ORDER_OPT),
                commandLine.getOptionValue(FalconCLIConstants.OFFSET_OPT),
                commandLine.getOptionValue(FalconCLIConstants.NUM_RESULTS_OPT),
                commandLine.getOptionValue(FalconCLIConstants.FIELDS_OPT));
        result = jobs != null ? jobs.toString() : "No extension job (" + extensionName + ") found.";
    } else if (optionsList.contains(INSTANCES_OPT)) {
        validateRequiredParameter(jobName, JOB_NAME_OPT);
        ExtensionInstanceList instances = client.listExtensionInstance(jobName, doAsUser,
                commandLine.getOptionValue(FalconCLIConstants.FIELDS_OPT),
                commandLine.getOptionValue(FalconCLIConstants.START_OPT),
                commandLine.getOptionValue(FalconCLIConstants.END_OPT),
                commandLine.getOptionValue(FalconCLIConstants.INSTANCE_STATUS_OPT),
                commandLine.getOptionValue(FalconCLIConstants.ORDER_BY_OPT),
                commandLine.getOptionValue(FalconCLIConstants.SORT_ORDER_OPT),
                commandLine.getOptionValue(FalconCLIConstants.OFFSET_OPT),
                commandLine.getOptionValue(FalconCLIConstants.NUM_RESULTS_OPT));
        result = instances != null ? instances.toString() : "No instance (" + jobName + ") found.";
    } else {
        throw new FalconCLIException("Invalid/missing extension command. Supported commands include "
                + "enumerate, definition, describe, list, instances, submit, submitAndSchedule, "
                + "schedule, suspend, resume, delete, update, validate. "
                + "Please refer to Falcon CLI twiki for more details.");
    }
    OUT.get().println(result);
}