Search in sources :

Example 16 with DefaultParser

use of org.apache.commons.cli.DefaultParser in project heron by twitter.

the class CppCheckstyle method main.

public static void main(String[] args) throws IOException {
    CommandLineParser parser = new DefaultParser();
    // create the Options
    Options options = new Options();
    options.addOption(Option.builder("f").required(true).hasArg().longOpt("extra_action_file").desc("bazel extra action protobuf file").build());
    options.addOption(Option.builder("c").required(true).hasArg().longOpt("cpplint_file").desc("Executable cpplint file to invoke").build());
    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);
        String extraActionFile = line.getOptionValue("f");
        String cpplintFile = line.getOptionValue("c");
        Collection<String> sourceFiles = getSourceFiles(extraActionFile);
        if (sourceFiles.size() == 0) {
            LOG.fine("No cpp files found by checkstyle");
            return;
        }
        LOG.fine(sourceFiles.size() + " cpp files found by checkstyle");
        // Create and run the command
        List<String> commandBuilder = new ArrayList<>();
        commandBuilder.add(cpplintFile);
        commandBuilder.add("--linelength=100");
        // TODO: https://github.com/twitter/heron/issues/466,
        // Remove "runtime/references" when we fix all non-const references in our codebase.
        // TODO: https://github.com/twitter/heron/issues/467,
        // Remove "runtime/threadsafe_fn" when we fix all non-threadsafe libc functions
        commandBuilder.add("--filter=-build/header_guard,-runtime/references,-runtime/threadsafe_fn");
        commandBuilder.addAll(sourceFiles);
        runLinter(commandBuilder);
    } catch (ParseException exp) {
        LOG.severe(String.format("Invalid input to %s: %s", CLASSNAME, exp.getMessage()));
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("java " + CLASSNAME, options);
    }
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) ArrayList(java.util.ArrayList) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 17 with DefaultParser

use of org.apache.commons.cli.DefaultParser in project streamsx.health by IBMStreams.

the class VinesAdapterService method main.

public static void main(String[] args) throws Exception {
    Option contextOption = Option.builder("c").longOpt("context-type").hasArg().argName("context type").required().build();
    Option hostOption = Option.builder("h").longOpt("host").hasArg().argName("host").required().build();
    Option portOption = Option.builder("p").longOpt("port").hasArg().argName("port").required().build();
    Option usernameOption = Option.builder("u").longOpt("username").hasArg().argName("username").required().build();
    Option passwordOption = Option.builder("P").longOpt("password").hasArg().argName("password").required().build();
    Option queueOption = Option.builder("q").longOpt("queue").hasArg().argName("queue").required().build();
    Option exchangeOption = Option.builder("e").longOpt("exchange").hasArg().argName("exchange name").required().build();
    Option debugOption = Option.builder("d").longOpt("debug").hasArg().argName("isDebugEnabled").required(false).type(Boolean.class).build();
    Option mappingEnabledOption = Option.builder("m").longOpt("mappingEnabled").hasArg().argName("isMappingEnabled").required().build();
    Options options = new Options();
    options.addOption(contextOption);
    options.addOption(hostOption);
    options.addOption(portOption);
    options.addOption(usernameOption);
    options.addOption(passwordOption);
    options.addOption(queueOption);
    options.addOption(exchangeOption);
    options.addOption(debugOption);
    options.addOption(mappingEnabledOption);
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("help", options);
        throw (e);
    }
    boolean isDebug = Boolean.valueOf(cmd.getOptionValue("d", Boolean.FALSE.toString()));
    HashMap<String, Object> params = new HashMap<String, Object>();
    params.put("hostAndPort", cmd.getOptionValue("h") + ":" + cmd.getOptionValue("p"));
    params.put("username", cmd.getOptionValue("u"));
    params.put("password", cmd.getOptionValue("P"));
    params.put("queueName", cmd.getOptionValue("q"));
    params.put("exchangeName", cmd.getOptionValue("e", ""));
    params.put("mappingEnabled", cmd.getOptionValue("m"));
    HashMap<String, Object> config = new HashMap<>();
    config.put(ContextProperties.SUBMISSION_PARAMS, params);
    if (isDebug) {
        config.put(ContextProperties.TRACING_LEVEL, TraceLevel.TRACE);
    }
    VinesAdapterService svc = new VinesAdapterService();
    svc.run(Type.valueOf(cmd.getOptionValue("c", "DISTRIBUTED")), config);
    if (isDebug) {
        // launch a debug service to print raw messages to the console
        Topology rawMsgTopo = new Topology("VinesRawMsgDebug");
        rawMsgTopo.subscribe(VinesAdapterService.VINES_DEBUG_TOPIC, String.class).print();
        StreamsContextFactory.getStreamsContext(Type.DISTRIBUTED).submit(rawMsgTopo).get();
        // launch a debug service to print Observation tuples to the console
        Topology obsTopo = new Topology("VinesObservationDebug");
        SubscribeConnector.subscribe(obsTopo, VinesAdapterService.VINES_TOPIC).print();
        StreamsContextFactory.getStreamsContext(Type.DISTRIBUTED).submit(obsTopo).get();
        // launch a debug service to print errors to the console
        Topology errTopo = new Topology("VinesErrorDebug");
        errTopo.subscribe(VinesAdapterService.VINES_ERROR_TOPIC, String.class).print();
        StreamsContextFactory.getStreamsContext(Type.DISTRIBUTED).submit(errTopo).get();
    }
}
Also used : Options(org.apache.commons.cli.Options) HashMap(java.util.HashMap) Topology(com.ibm.streamsx.topology.Topology) HelpFormatter(org.apache.commons.cli.HelpFormatter) CommandLine(org.apache.commons.cli.CommandLine) Option(org.apache.commons.cli.Option) JsonObject(com.google.gson.JsonObject) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 18 with DefaultParser

use of org.apache.commons.cli.DefaultParser in project streamsx.health by IBMStreams.

the class PrintService method main.

public static void main(String[] args) throws Exception {
    Option subscribeTopicOption = Option.builder("s").longOpt("subscribe-topic").hasArg().argName("subscribe topic").required().build();
    Option contextTypeOption = Option.builder("c").longOpt("context-type").hasArg().argName("context type").required(false).build();
    Options options = new Options();
    options.addOption(subscribeTopicOption);
    options.addOption(contextTypeOption);
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("help", options);
        throw (e);
    }
    Type contextType = Type.valueOf(cmd.getOptionValue("c", Type.DISTRIBUTED.name()));
    String subscribeTopic = cmd.getOptionValue("s");
    PrintService svc = new PrintService(subscribeTopic);
    svc.run(contextType, new HashMap<String, Object>());
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) Type(com.ibm.streamsx.topology.context.StreamsContext.Type) Option(org.apache.commons.cli.Option) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 19 with DefaultParser

use of org.apache.commons.cli.DefaultParser in project streamsx.health by IBMStreams.

the class AbstractEventService method launchService.

protected static void launchService(String[] args, Class<? extends AbstractEventService> eventServiceClass) throws Exception {
    Option hostOption = Option.builder("x").longOpt("host").hasArg().argName("watson explorer host").required().build();
    Option portOption = Option.builder("p").longOpt("port").hasArg().argName("watson explorer port").required().build();
    Option collectionOption = Option.builder("c").longOpt("collection").hasArg().argName("collection name").required().build();
    Option patientIdFieldOption = Option.builder("f").longOpt("patient-field").hasArg().argName("patient ID field name").required(false).build();
    Option toolkitOption = Option.builder("t").longOpt("toolkit-path").hasArg().argName("watson explorer toolkit path").required().build();
    Option subscribeOption = Option.builder("s").longOpt("subscription-topic").hasArg().argName("subscription topic").required().build();
    Option debugOption = Option.builder("d").longOpt("debug").hasArg().argName("isDebugEnabled").required(false).type(Boolean.class).build();
    Options options = new Options();
    options.addOption(hostOption);
    options.addOption(portOption);
    options.addOption(collectionOption);
    options.addOption(patientIdFieldOption);
    options.addOption(toolkitOption);
    options.addOption(subscribeOption);
    options.addOption(debugOption);
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("help", options);
        throw (e);
    }
    boolean isDebug = cmd.getOptionValue("d", "false").equals("true");
    AbstractEventService svc = eventServiceClass.getConstructor(String.class).newInstance(cmd.getOptionValue("t"));
    //MedicationEventService svc = new MedicationEventService(cmd.getOptionValue("t"));
    svc.setContextType(Type.DISTRIBUTED);
    svc.addSubmissionTimeParam("wex.host", cmd.getOptionValue("x"));
    svc.addSubmissionTimeParam("wex.port", Integer.valueOf(cmd.getOptionValue("p")));
    svc.addSubmissionTimeParam("wex.patient.field.name", cmd.getOptionValue("f", "patient_id"));
    svc.addSubmissionTimeParam("collectionName", cmd.getOptionValue("c"));
    svc.setSubscriptionTopic(cmd.getOptionValue("s"));
    if (isDebug) {
        svc.setTraceLevel(TraceLevel.TRACE);
    }
    svc.buildAndRun();
    if (isDebug) {
        new EventBeacon(svc.getPublishedTopic()).run();
    }
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) Option(org.apache.commons.cli.Option) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 20 with DefaultParser

use of org.apache.commons.cli.DefaultParser in project tika by apache.

the class TikaEvalCLI method handleProfile.

private void handleProfile(String[] subsetArgs) throws Exception {
    List<String> argList = new ArrayList(Arrays.asList(subsetArgs));
    boolean containsBC = false;
    String inputDir = null;
    String extracts = null;
    String alterExtract = null;
    //confirm there's a batch-config file
    for (int i = 0; i < argList.size(); i++) {
        String arg = argList.get(i);
        if (arg.equals("-bc")) {
            containsBC = true;
        } else if (arg.equals("-inputDir")) {
            if (i + 1 >= argList.size()) {
                System.err.println("Must specify directory after -inputDir");
                ExtractProfiler.USAGE();
                return;
            }
            inputDir = argList.get(i + 1);
            i++;
        } else if (arg.equals("-extracts")) {
            if (i + 1 >= argList.size()) {
                System.err.println("Must specify directory after -extracts");
                ExtractProfiler.USAGE();
                return;
            }
            extracts = argList.get(i + 1);
            i++;
        } else if (arg.equals("-alterExtract")) {
            if (i + 1 >= argList.size()) {
                System.err.println("Must specify type 'as_is', 'first_only' or " + "'concatenate_content' after -alterExtract");
                ExtractComparer.USAGE();
                return;
            }
            alterExtract = argList.get(i + 1);
            i++;
        }
    }
    if (alterExtract != null && !alterExtract.equals("as_is") && !alterExtract.equals("concatenate_content") && !alterExtract.equals("first_only")) {
        System.out.println("Sorry, I don't understand:" + alterExtract + ". The values must be one of: as_is, first_only, concatenate_content");
        ExtractProfiler.USAGE();
        return;
    }
    //this allows the user to specify either extracts or inputDir
    if (extracts == null && inputDir != null) {
        argList.add("-extracts");
        argList.add(inputDir);
    } else if (inputDir == null && extracts != null) {
        argList.add("-inputDir");
        argList.add(extracts);
    }
    Path tmpBCConfig = null;
    try {
        tmpBCConfig = Files.createTempFile("tika-eval-profiler", ".xml");
        if (!containsBC) {
            Files.copy(this.getClass().getResourceAsStream("/tika-eval-profiler-config.xml"), tmpBCConfig, StandardCopyOption.REPLACE_EXISTING);
            argList.add("-bc");
            argList.add(tmpBCConfig.toAbsolutePath().toString());
        }
        String[] updatedArgs = argList.toArray(new String[argList.size()]);
        DefaultParser defaultCLIParser = new DefaultParser();
        try {
            CommandLine commandLine = defaultCLIParser.parse(ExtractProfiler.OPTIONS, updatedArgs);
            if (commandLine.hasOption("db") && commandLine.hasOption("jdbc")) {
                System.out.println("Please specify either the default -db or the full -jdbc, not both");
                ExtractProfiler.USAGE();
                return;
            }
        } catch (ParseException e) {
            System.out.println(e.getMessage() + "\n");
            ExtractProfiler.USAGE();
            return;
        }
        FSBatchProcessCLI.main(updatedArgs);
    } finally {
        if (tmpBCConfig != null && Files.isRegularFile(tmpBCConfig)) {
            Files.delete(tmpBCConfig);
        }
    }
}
Also used : Path(java.nio.file.Path) CommandLine(org.apache.commons.cli.CommandLine) ArrayList(java.util.ArrayList) ParseException(org.apache.commons.cli.ParseException) DefaultParser(org.apache.commons.cli.DefaultParser)

Aggregations

CommandLine (org.apache.commons.cli.CommandLine)41 DefaultParser (org.apache.commons.cli.DefaultParser)41 CommandLineParser (org.apache.commons.cli.CommandLineParser)29 ParseException (org.apache.commons.cli.ParseException)28 Options (org.apache.commons.cli.Options)27 HelpFormatter (org.apache.commons.cli.HelpFormatter)13 Option (org.apache.commons.cli.Option)9 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 IOException (java.io.IOException)5 Config (com.twitter.heron.spi.common.Config)3 Path (java.nio.file.Path)3 Level (java.util.logging.Level)3 Topology (com.ibm.streamsx.topology.Topology)2 PackingException (com.twitter.heron.spi.packing.PackingException)2 File (java.io.File)2 PrintStream (java.io.PrintStream)2 Properties (java.util.Properties)2 Test (org.junit.Test)2 PropertyKey (alluxio.PropertyKey)1