/** * Usage: URPChecker \ * -brokerstatszk datazk001:2181/data07 \ * -brokerstatstopic brokerstats \ * -clusterzk m10nzk001:2181,...,m10nzk007:2181/m10n07 */ private static CommandLine parseCommandLine(String[] args) { Option zookeeper = new Option(ZOOKEEPER, true, "cluster zookeeper"); options.addOption(zookeeper); if (args.length < 2) { printUsageAndExit(); } CommandLineParser parser = new DefaultParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException | NumberFormatException e) { printUsageAndExit(); } return cmd; }
public static void main(String[] args) throws Exception { CommandLineParser parser = new DefaultParser(); CommandLine line = parser.parse(CLI_OPTIONS, args); if (!line.hasOption("conf")) { System.err.println("No configuration file is specified"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("athenax-server", CLI_OPTIONS); System.exit(1); } try { String confFile = line.getOptionValue("conf"); AthenaXConfiguration conf = AthenaXConfiguration.load(Paths.get(confFile).toFile()); new AthenaXServer().start(conf); } catch (IOException | ClassNotFoundException e) { System.err.println("Failed to parse configuration."); throw e; } }
public final static void main(String[] args) throws Exception { logger.debug(format("%s called with arguments: '%s'.", GetChangeStatus.class.getSimpleName(), Commands.Helpers.getArgsLogString(args))); Options options = new Options(); Commands.Helpers.addStandardParameters(options); if(helpRequested(args)) { handleHelpOption(format("%s <changeId>", getCommandName(GetChangeStatus.class)), "Returns 'true' if the change specified by <changeId> is in development. Otherwise 'false'.", new Options()); return; } CommandLine commandLine = new DefaultParser().parse(options, args); new GetChangeStatus( getHost(commandLine), getUser(commandLine), getPassword(commandLine), getChangeId(commandLine)).execute(); }
protected static void main(Class<? extends TransportRelated> clazz, String[] args, String usage, String helpText) throws Exception { logger.debug(format("%s called with arguments: %s", clazz.getSimpleName(), Commands.Helpers.getArgsLogString(args))); Options options = new Options(); Commands.Helpers.addStandardParameters(options); if(helpRequested(args)) { handleHelpOption(usage, helpText, new Options()); return; } CommandLine commandLine = new DefaultParser().parse(options, args); newInstance(clazz, getHost(commandLine), getUser(commandLine), getPassword(commandLine), getChangeId(commandLine), getTransportId(commandLine)).execute(); }
private static String getCommandName(String[] args) throws ParseException { Options opts = new Options(); asList(CMOptions.HELP, CMOptions.VERSION, CMOptions.HOST, CMOptions.USER, CMOptions.PASSWORD).stream().map( new Function<Option, Option>() { @Override public Option apply(Option o) { Option c = CMOptions.clone(o); c.setRequired(false); return c; } }).forEach(o -> opts.addOption(o)); CommandLine parser = new DefaultParser().parse(opts, args, true); if(parser.getArgs().length == 0) { throw new CMCommandLineException(format("Canmnot extract command name from arguments: '%s'.", getArgsLogString(args))); } String commandName = parser.getArgs()[0]; logger.debug(format("Command name '%s' extracted from command line '%s'.", commandName, getArgsLogString(args))); return commandName; }
public final static void main(String[] args) throws Exception { logger.debug(format("%s called with arguments: '%s'.", GetChangeTransports.class.getSimpleName(), Commands.Helpers.getArgsLogString(args))); Options options = new Options(); Commands.Helpers.addStandardParameters(options); options.addOption(modifiableOnlyOption); if(helpRequested(args)) { handleHelpOption(format("%s [SUBCOMMAND_OPTIONS] <changeId>", getCommandName(GetChangeTransports.class)), "Returns the ids of the transports for the change represented by <changeId>.", new Options().addOption(modifiableOnlyOption)); return; } CommandLine commandLine = new DefaultParser().parse(options, args); new GetChangeTransports( getHost(commandLine), getUser(commandLine), getPassword(commandLine), getChangeId(commandLine), commandLine.hasOption(modifiableOnlyOption.getOpt())).execute(); }
public final static void main(String[] args) throws Exception { logger.debug(format("%s called with arguments: '%s'.", ReleaseTransport.class.getSimpleName(), Commands.Helpers.getArgsLogString(args))); Options options = new Options(); Commands.Helpers.addStandardParameters(options); if(helpRequested(args)) { handleHelpOption( format("%s <changeId> <transportId>", getCommandName(ReleaseTransport.class)), "Releases the transport specified by <changeId>, <transportId>.", new Options()); return; } CommandLine commandLine = new DefaultParser().parse(options, args); new ReleaseTransport(getHost(commandLine), getUser(commandLine), getPassword(commandLine), getChangeId(commandLine), TransportRelated.getTransportId(commandLine)).execute(); }
public final static void main(String[] args) throws Exception { logger.debug(format("%s called with arguments: '%s'.", UploadFileToTransport.class.getSimpleName(), Commands.Helpers.getArgsLogString(args))); Options options = new Options(); Commands.Helpers.addStandardParameters(options); if(helpRequested(args)) { handleHelpOption(format("%s <changeId> <transportId> <applicationId> <filePath>", getCommandName(UploadFileToTransport.class)), "Uploads the file specified by <filePath> to transport <transportId> for change <changeId>. " + "<applicationId> specifies how the file needs to be handled on server side.", new Options()); return; } CommandLine commandLine = new DefaultParser().parse(options, args); new UploadFileToTransport( getHost(commandLine), getUser(commandLine), getPassword(commandLine), getChangeId(commandLine), getArg(commandLine, 2, "transportId"), getArg(commandLine, 3, "applicationId"), getArg(commandLine, 4, "filePath")).execute(); }
/** * "Parsing" stage of command-line processing demonstrated with * Apache Commons CLI. * * @param options Options from "definition" stage. * @param commandLineArguments Command-line arguments provided to application. * @return Instance of CommandLine as parsed from the provided Options and * command line arguments; may be {@code null} if there is an exception * encountered while attempting to parse the command line options. */ private static CommandLine generateCommandLine( final Options options, final String[] commandLineArguments) { final CommandLineParser cmdLineParser = new DefaultParser(); CommandLine commandLine = null; try { commandLine = cmdLineParser.parse(options, commandLineArguments); } catch (ParseException parseException) { out.println( "ERROR: Unable to parse command-line arguments " + Arrays.toString(commandLineArguments) + " due to: " + parseException); } return commandLine; }
private void processArguments(String[] args) throws org.apache.commons.cli.ParseException { Options opts = new Options(); // Setting CLI options opts.addOption("gui", "Whether to use the GUI or not. ('yes' or 'no')"); opts.addOption("help", "Shows this page"); opts.addOption("license", "Show license info."); CommandLine cl = new DefaultParser().parse(opts, args); // Parsing // CLI // options if (cl.hasOption("help")) showHelp(); if (cl.hasOption("license")) showLicense(); setGui(cl.hasOption("gui")); }
public static void main(String[] args) { Options options = new Options(); options.addOption("h", true, "Messaging host"); options.addOption("p", true, "Messaging port"); options.addOption("q", true, "Queue"); options.addOption("u", false, "Print this help"); CommandLineParser parser = new DefaultParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("u")) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("Sender", options); } else { String messagingHost = cmd.getOptionValue("h", MESSAGING_HOST); int messagingPort = Integer.parseInt(cmd.getOptionValue("p", String.valueOf(MESSAGING_PORT))); String address = cmd.getOptionValue("q", QUEUE); Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory"); props.put("connectionfactory.myFactoryLookup", String.format("amqp://%s:%d", messagingHost, messagingPort)); props.put("queue.myDestinationLookup", address); LOG.info("Starting server : connecting to [{}:{}]", messagingHost, messagingPort); Server sender = new Server(); sender.run(props); } } catch (ParseException e) { e.printStackTrace(); } }
static void parseForHelp(String[] args) { // parse for help options try { Options helpOnly = new Options(); helpOnly.addOption(options.getOption("h")); CommandLine cli = new DefaultParser().parse(helpOnly, args, true); // no -h option - do nothing if (!cli.hasOption("h")) { return; } } catch (ParseException pe) { System.err.println(pe.getMessage()); System.exit(-1); } // print help text new HelpFormatter().printHelp("java -jar sgc-xxx.jar", "Simple Glacier Client (sgc) | Version: 0.1\n\n", options, "\n"+"See: https://github.com/arjuan/simple-glacier-client"+"\n\n", true); }
private static CommandLine parseCommandLine(String[] args) { if (args.length < 4) { printUsageAndExit(); } Option zookeeper = new Option(ZOOKEEPER, true, "zookeeper connection string"); Option statsTopic = new Option(STATS_TOPIC, true, "kafka topic for broker stats"); options.addOption(zookeeper).addOption(statsTopic); CommandLineParser parser = new DefaultParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException | NumberFormatException e) { printUsageAndExit(); } return cmd; }
private static CommandLine parseCommandLine(String[] args) { Option host = new Option(BROKER_NAME, true, "kafka broker"); Option jmxPort = new Option(JMX_PORT, true, "kafka jmx port number"); jmxPort.setArgName("kafka jmx port number"); Option metric = new Option(METRICS_NAME, true, "jmx metric name"); options.addOption(jmxPort).addOption(host).addOption(metric); if (args.length < 4) { printUsageAndExit(); } CommandLineParser parser = new DefaultParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException | NumberFormatException e) { printUsageAndExit(); } return cmd; }
/** * Usage: ReplicaStatsRetriever \ * -brokerstatszk datazk001:2181/data07 \ * -brokerstatstopic brokerstats \ * -clusterzk m10nzk001:2181,...,m10nzk007:2181/m10n07 \ * -seconds 43200 */ private static CommandLine parseCommandLine(String[] args) { Option config = new Option(CONFIG, true, "operator config"); Option brokerStatsZookeeper = new Option(BROKERSTATS_ZOOKEEPER, true, "zookeeper for brokerstats topic"); Option brokerStatsTopic = new Option(BROKERSTATS_TOPIC, true, "topic for brokerstats"); Option clusterZookeeper = new Option(CLUSTER_ZOOKEEPER, true, "cluster zookeeper"); Option seconds = new Option(SECONDS, true, "examined time window in seconds"); options.addOption(config).addOption(brokerStatsZookeeper).addOption(brokerStatsTopic) .addOption(clusterZookeeper).addOption(seconds); if (args.length < 6) { printUsageAndExit(); } CommandLineParser parser = new DefaultParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException | NumberFormatException e) { printUsageAndExit(); } return cmd; }
/** * Usage: ClusterLoadBalancer \ * -brokerstatszk zookeeper001:2181/cluster1 \ * -brokerstatstopic brokerstats \ * -clusterzk zookeeper001:2181,...,zookeeper007:2181/cluster2 \ * -brokerids 2048,2051 -seconds 43200 * -onlyone */ private static CommandLine parseCommandLine(String[] args) { Option brokerStatsZookeeper = new Option(BROKERSTATS_ZOOKEEPER, true, "zookeeper for brokerstats topic"); Option config = new Option(CONFIG, true, "doctorkafka config"); Option brokerStatsTopic = new Option(BROKERSTATS_TOPIC, true, "topic for brokerstats"); Option clusterZookeeper = new Option(CLUSTER_ZOOKEEPER, true, "cluster zookeeper"); Option seconds = new Option(SECONDS, true, "examined time window in seconds"); Option onlyOne = new Option(ONLY_ONE, false, "only balance broker that has the heaviest load"); options.addOption(config).addOption(brokerStatsZookeeper).addOption(brokerStatsTopic) .addOption(clusterZookeeper).addOption(seconds).addOption(onlyOne); if (args.length < 6) { printUsageAndExit(); } CommandLineParser parser = new DefaultParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException | NumberFormatException e) { printUsageAndExit(); } return cmd; }
/** * Usage: BrokerStatsRetriever \ * --brokerstatszk datazk001:2181/data07 \ * --brokerstatstopic brokerstats \ * --broker kafkabroker001 */ private static CommandLine parseCommandLine(String[] args) { Option config = new Option(CONFIG, true, "operator config"); Option brokerStatsZookeeper = new Option(BROKERSTATS_ZOOKEEPER, true, "zookeeper for brokerstats topic"); Option brokerStatsTopic = new Option(BROKERSTATS_TOPIC, true, "topic for brokerstats"); Option broker = new Option(BROKERNAME, true, "broker name"); options.addOption(config).addOption(brokerStatsZookeeper).addOption(brokerStatsTopic) .addOption(broker); if (args.length < 6) { printUsageAndExit(); } CommandLineParser parser = new DefaultParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException | NumberFormatException e) { printUsageAndExit(); } return cmd; }
/** * Usage: KafkaWriter \ * --zookeeper zookeeper001:2181/cluster1 --topic kafka_test \ * --message "this is a test message" */ private static CommandLine parseCommandLine(String[] args) { Option zookeeper = new Option(ZOOKEEPER, true, "zookeeper connection string"); Option topic = new Option(TOPIC, true, "action report topic name"); Option message = new Option(MESSAGE, true, "messags that writes to kafka"); options.addOption(zookeeper).addOption(topic).addOption(message); if (args.length < 6) { printUsageAndExit(); } CommandLineParser parser = new DefaultParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException | NumberFormatException e) { printUsageAndExit(); } return cmd; }
/** * Usage: KafkaWriter \ * --zookeeper datazk001:2181/testk10 --topic kafka_test \ * --num_messages 100 */ private static CommandLine parseCommandLine(String[] args) { Option zookeeper = new Option(ZOOKEEPER, true, "zookeeper connection string"); Option topic = new Option(TOPIC, true, "topic that KafkaWriter writes to"); Option num_messages = new Option(NUM_MESSAGES, true, "num of messags that writes to kafka"); options.addOption(zookeeper).addOption(topic).addOption(num_messages); if (args.length < 6) { printUsageAndExit(); } CommandLineParser parser = new DefaultParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException | NumberFormatException e) { printUsageAndExit(); } return cmd; }
/** * Usage: OperatorActionRetriever \ * -zookeeper datazk001:2181/data07 \ * -topic operator_report -num_messages 1000 */ private static CommandLine parseCommandLine(String[] args) { Option zookeeper = new Option(ZOOKEEPER, true, "doctorkafka action zookeeper"); Option topic = new Option(TOPIC, true, "doctorkafka action topic"); Option num_messages = new Option(NUM_MESSAGES, true, "num of messages to retrieve"); options.addOption(zookeeper).addOption(topic).addOption(num_messages); if (args.length < 2) { printUsageAndExit(); } CommandLineParser parser = new DefaultParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException | NumberFormatException e) { printUsageAndExit(); } return cmd; }
public static void main(String[] args) throws InterruptedException { Options options = getOptions(); try { CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); String[] streamId = StringUtils.split(cmd.getOptionValue("stream", DEFAULT_STREAM_ID), '/'); if(streamId.length != 2) { throw new IllegalArgumentException("Stream spec must be in the form [scope]/[stream]"); } final URI controllerURI = URI.create(cmd.getOptionValue("uri", DEFAULT_CONTROLLER_URI)); new NoopReader().run(streamId[0], streamId[1], controllerURI); } catch (ParseException e) { System.out.format("%s.%n", e.getMessage()); final HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("NoopReader", options); System.exit(1); } }
public static void main(String[] args) { CommandLineParser parser = new DefaultParser(); try { // parse the command line arguments CommandLine line = parser.parse(buildOptions(), args); if (line.hasOption('h')) { printHelp(); System.exit(0); } if (line.hasOption('v')) { System.out.println(VERSION_STRING); System.exit(0); } new CommandLineApp(System.out, line).extractTables(line); } catch (ParseException exp) { System.err.println("Error: " + exp.getMessage()); System.exit(1); } System.exit(0); }
public static void main(String[] args) { CommandLineParser parser = new DefaultParser(); try { Options options = getOptions(); CommandLine line = parser.parse(options, args ); if (line.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); System.out.println(Constants.PROJECT_NAME + ", " + Constants.PROJECT_URL); formatter.printHelp(Constants.PROJECT_NAME, options, true); } else if (line.hasOption("version")) { System.out.println("version: " + Constants.VERSION); } else { logger.info("Starting pm-home-station ({} v.{})...", Constants.PROJECT_URL, Constants.VERSION); setLookAndFeel(); PlanTowerSensor planTowerSensor = new PlanTowerSensor(); Station station = new Station(planTowerSensor); SwingUtilities.invokeLater(() -> { station.showUI(); }); } } catch (ParseException e) { logger.error("Ooops", e); return; } }
@Override public String render(ProofTreeModelElement tree, String[] args) { final Options clopt = new Options(); clopt.addOption(Option.builder("f").longOpt("fit-to-page") .hasArg(false).desc("Fit proof tree to page size") .required(false).build()); CommandLineParser parser = new DefaultParser(); try { CommandLine parsed = parser.parse(clopt, args); if (parsed.hasOption("f")) { fitToPage = true; } } catch (ParseException e) { System.err.println("Error in parsing arguments for renderer:"); System.err.println(e.getLocalizedMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("--renderer-args \"...\"", clopt); } return render(tree); }
@Test public void test() throws Exception { Options options = new Options(); CliOptions.addOptions(options); CommandLine cmd = new DefaultParser().parse(options, new String[]{"--android", "-f", "ic_launcher.svg"}); OutputConfig cfg = CliOptions.parse(cmd); assertNull(cfg.getInputDirectory()); assertNull(cfg.getOutputDirectory()); assertNull(cfg.getOutputName()); assertEquals(5, cfg.getFiles().size()); assertEquals("ic_launcher.svg", cfg.getInputFile()); for (FileOutput fo : cfg.getFiles()) { final String outPath = fo.toOutputFile(new File("ic_launcher.svg"), null, null).getAbsolutePath(); System.out.println(outPath); assertTrue(!outPath.startsWith("null/")); assertTrue(outPath.endsWith("/ic_launcher.png")); } }
@Override public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException { final ProcessorLog log = this.getLogger(); final AtomicReference<byte[]> value = new AtomicReference<>(); String preprocessingDef = context.getProperty(DEFINITIONS).getValue(); String tempDir = context.getProperty(TEMP_DIR).getValue(); String convertPath = context.getProperty(CONVERT_PATH).getValue(); CommandLine cli = CleaningOptions.parse(new DefaultParser(), CLIUtils.translateCommandline(preprocessingDef) ); final TextCleaner cleaner = CleaningOptions.createTextCleaner(cli, convertPath, tempDir); FlowFile flowfile = session.get(); session.read(flowfile, in -> { try { value.set(cleaner.convert(in)); } catch (Exception e) { value.set(IOUtils.toByteArray(in)); log.error("Unable to execute command: " + e.getMessage(), e); } }); flowfile = session.write(flowfile, out -> { out.write(value.get()); out.flush(); }); session.transfer(flowfile, SUCCESS); }
@Test public void happyPathTest() throws IOException, CommandFailedException { String input = "src/test/resources/images/brscan_original_r90.jpg"; BufferedImage inputImage = ImageUtils.INSTANCE.readImage(new File(input)); Assert.assertEquals(1024, inputImage.getHeight()); Assert.assertEquals(768, inputImage.getWidth()); String output = "src/test/resources/images/brscan_original_r90-out.jpg"; String args = "-g -e normalize -f 15 -o 10 -u -s 2 -T -p 20"; DefaultParser parser = new DefaultParser(); CommandLine cli = CleaningOptions.parse(parser, CLIUtils.translateCommandline(args) ); TextCleaner cleaner = CleaningOptions.createTextCleaner(cli, null); String commandLine = Joiner.on(" ").join(cleaner.getCommandLine(input, output)); Assert.assertNotNull(commandLine); Assert.assertEquals("-respect-parenthesis ( src/test/resources/images/brscan_original_r90.jpg -colorspace gray -type grayscale ) ( -clone 0 -colorspace gray -negate -lat 15x15+10% -contrast-stretch 0 ) -compose copy_opacity -composite -fill white -opaque none -alpha off -background white -deskew 40% -sharpen 0x2 -trim +repage -compose over -bordercolor white -border 20 src/test/resources/images/brscan_original_r90-out.jpg" , commandLine ); byte[] result = cleaner.convert(input, ".jpg"); Assert.assertTrue(result.length > 0); BufferedImage outputImage = ImageUtils.INSTANCE.readImage(result); Assert.assertEquals(1074, outputImage.getHeight()); Assert.assertEquals(812, outputImage.getWidth()); }
public ScanConfig(String[] inputArgs) { Options o = new Options(); o.addOption(Option.builder("bucket").desc("S3 Bucket Name").hasArg().required().build()); o.addOption(Option.builder("prefix").desc("S3 Bucket Prefix").hasArg().build()); o.addOption( Option.builder("filter").desc("Key Filter Regex. Default '" + defaultFilter + "'").hasArg().build()); o.addOption( Option.builder("profile").desc("AWS Credential Profile Name (in ~/.aws/credentials). Default 'default'") .hasArg().build()); o.addOption(Option.builder("queue").desc("SQS Queue to populate. Will create if it doesn't exit.") .hasArg().required().build()); o.addOption(Option.builder("max").desc("Max number of images to add to queue.").hasArg().build()); o.addOption(Option.builder("help").desc("Get this help.").build()); options = o; try { CommandLineParser parser = new DefaultParser(); args = parser.parse(o, inputArgs); } catch (ParseException e) { threw = true; } }
private static String getCLIArgs(String[] args) throws ParseException { Options options = new Options(); options.addOption("q", true, "repository search term"); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); if (!cmd.hasOption("q")) { System.out.println("Please enter a search term (-q)"); System.exit(1); } String searchTerm = cmd.getOptionValue("q"); System.out.printf("searching for => \"%s\" ... \n", searchTerm); if (searchTerm == null || searchTerm.equals("") || searchTerm.length() < 3) { System.out.println("Sorry your search term may not be empty or less than 3 chars"); System.exit(1); } return searchTerm; }
@Test public void testUmlauts() throws Exception { Configuration configuration = new Configuration(); reader.configuration = configuration; Options options = new Options(); options.addOption(Configuration.SWITCH_USE_THIS_YAML_FILE, true, "Not needed."); CommandLineParser parser = new DefaultParser(); String[] args = {"-file", "src/test/resources/testumlauts.yaml"}; CommandLine commandLine = parser.parse(options, args); configuration.setParameter(commandLine); Map<String, Object> stringObjectMap = reader.readYamlFile("src/test/resources/testumlauts.yaml"); ObjectMapper mapper = new ObjectMapper(); String valueAsString = mapper.writeValueAsString(stringObjectMap); Map<String, Object> result = mapper.readValue(valueAsString, Map.class); assertThat(result).isEqualTo(stringObjectMap); }
/** * @param args the command line arguments * @throws java.rmi.RemoteException */ public static void main(String[] args) throws RemoteException, IOException { SystemHelper.enableRmiServer(); Options options = initOptions(); CommandLineParser parser = new DefaultParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("help")) { displayHelp(options); } else if (cmd.hasOption("version")) { displayVersion(); } else { Server server = new Server(cmd); } } catch (ParseException ex) { Xlog.timedErr(ex.getMessage()); System.out.println(sBundle.getString("parse_help_server")); } }
public CommandLineArguments parseCommandLine(String[] args) throws ParseException { Options options = new Options(); Option source = new Option(SOURCE_SHORT, SOURCE_LONG, true, "source yaml file"); source.setRequired(true); options.addOption(source); Option override = new Option(OVERRIDE_SHORT, OVERRIDE_LONG, true, "override yaml file"); override.setRequired(true); options.addOption(override); CommandLineParser parser = new DefaultParser(); try { CommandLine cmd = parser.parse(options, args); String sourceFile = cmd.getOptionValue(SOURCE_LONG); String overrideFile = cmd.getOptionValue(OVERRIDE_LONG); return new CommandLineArguments(new File(sourceFile), new File(overrideFile)); } catch (ParseException e) { System.out.println(e.getMessage()); new HelpFormatter().printHelp("yaml-merge", options); throw e; } }
private void readArgs(String[] args) { CommandLineParser parser = new DefaultParser(); try { CommandLine cmd = parser.parse(options, args); labelFile = getFileFromOption(cmd, OPTION_LABEL_FILE); geolocationDbFile = getFileFromOption(cmd, OPTION_GEOLOCATION_DB_FILE); geolocationFeatureFile = getFileFromOption(cmd, OPTION_GEOLOCATION_FEATURE_FILE); revisionTagFile = getFileFromOption(cmd, OPTION_REVISION_TAG_FILE); List<String> argList = cmd.getArgList(); if (argList.size() != 2) { printHelp(); } else { revisionFile = new File(argList.get(0)); featureFile = new File(argList.get(1)); } } catch (ParseException exp) { System.err.print(exp); } }
private CommandLine parseCommandLine(String... args) { args = CommandUtils.firstCommand(args); CommandLineParser parser = new DefaultParser(); CommandLine commandLine = null; try { Optional<CommandInfo> commandInfo = registry.commands().stream() .filter(c -> c.className().equals(getClass().getName())).findFirst(); if (commandInfo.isPresent()) { Options options = new Options(); commandInfo.get().options().getOptions().forEach(options::addOption); commandInfo.get().globalOptions().getOptions().forEach(options::addOption); commandLine = parser.parse(options, args); CommandLineOptions.set(commandLine); } return commandLine; } catch (ParseException e) { throw new CommandException(ParseExceptionProcessor.process(e), (String) null); } }
public static void main(String[] args) { final CommandLineParser parser = new DefaultParser(); final Options options = new Options() .addOption(Option.builder("c").hasArg(true).desc("experiment configuration file").required().build()) .addOption(Option.builder("g").hasArg(true).desc("goal to run").build()) .addOption(Option.builder("p").hasArg(true).desc("port").build()); try { CommandLine commandLine = parser.parse(options, args); final Pipegraph graph = new Pipegraph( new File("results"), new File(commandLine.getOptionValue("c")), Optional.of(commandLine) .filter(cl -> cl.hasOption("g")) .map(cl -> cl.getOptionValue("g")) .map(ImmutableList::of)); final IPipegraphRunner runner = new AsynchronousPipegraphRunner(); runner.run(graph, Optional.of(commandLine) .filter(cl -> cl.hasOption("p")) .map(cl -> cl.getOptionValue("p")) .map(Integer::parseInt)); } catch (final ParseException exp) { System.err.println(exp.getMessage()); } }
public Cli(PrintWriter out, String... args) throws ParseException, CliException { this.out = out; Options options = new Options(); options.addOption("h", "help", false, "Show help"); options.addOption("r", "rulesPath", true, "The resolving rulesPath to map names to images or manifests"); options.addOption("p", "spring.profiles.active", true, "The active spring configuration"); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("help")) { showHelp(options); exitStatus = ExitStatus.OK; return; } if (cmd.hasOption("rulesPath")) { rulesPath = cmd.getOptionValue("rulesPath"); validateRulesPath(); } if (cmd.hasOption("spring.profiles.active")) { springProfiles = cmd.getOptionValue("spring.profiles.active"); } }
private static CommandLine getCommandLineArgs() { CommandLine cmd = null; try { String commandArgs = System.getProperty("sun.java.command"); CommandLineParser parser = new DefaultParser(); Options options = new Options(); options.addOption("s", "settings", true, "Alternate path for the user settings file"); options.addOption("gs", "global-settings", true, "Alternate path for the global settings file"); cmd = parser.parse(options, commandArgs.split(" ")); } catch (Exception e) { // ignore unparsable command line args } return cmd; }
/** * Print the command line options help message and exit application. */ @SuppressWarnings("static-access") private static void showHelpMessage(String[] args, Options options) { Options helpOptions = new Options(); helpOptions.addOption(Option.builder("h").longOpt("help") .desc("print this message").build()); try { CommandLine helpLine = new DefaultParser().parse(helpOptions, args, true); if (helpLine.hasOption("help") || args.length == 1) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("truck-events-kafka-ingest", options); System.exit(0); } } catch (ParseException ex) { LOG.error("Parsing failed. Reason: " + ex.getMessage()); System.exit(1); } }
private void getCliOptions(String[] args) { cliOptions = new Options(); Option configfileOpt = new Option("c", "configfile", true, "config file path"); configfileOpt.setRequired(true); cliOptions.addOption(configfileOpt); CommandLineParser parser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); CommandLine cmd; try { cmd = parser.parse(cliOptions, args); } catch (ParseException e) { System.out.println(e.getMessage()); formatter.printHelp("utility-name", cliOptions); System.exit(1); return; } this.configfile = cmd.getOptionValue("configfile"); }