com.beust.jcommander.ParameterException Java Examples
The following examples show how to use
com.beust.jcommander.ParameterException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CreateRegistrarCommandTest.java From nomulus with Apache License 2.0 | 6 votes |
@Test public void testFailure_nonIntegerBillingId() { assertThrows( ParameterException.class, () -> runCommandForced( "--name=blobio", "--password=some_password", "--registrar_type=REAL", "--iana_id=8", "--billing_id=ABC12345", "--passcode=01234", "[email protected]", "--street=\"123 Fake St\"", "--city Fakington", "--state MA", "--zip 00351", "--cc US", "clientz")); }
Example #2
Source File: HelpCommand.java From emissary with Apache License 2.0 | 6 votes |
@Override public void run(JCommander jc) { setup(); if (subcommands.size() == 0) { dumpCommands(jc); } else if (subcommands.size() > 1) { LOG.error("You can only see help for 1 command at a time"); dumpCommands(jc); } else { String subcommand = getSubcommand(); LOG.info("Detailed help for: " + subcommand); try { jc.usage(subcommand); } catch (ParameterException e) { LOG.error("ERROR: invalid command name: " + subcommand); dumpCommands(jc); } } }
Example #3
Source File: Help.java From accumulo-examples with Apache License 2.0 | 6 votes |
public void parseArgs(String programName, String[] args, Object... others) { JCommander commander = new JCommander(); commander.addObject(this); for (Object other : others) commander.addObject(other); commander.setProgramName(programName); try { commander.parse(args); } catch (ParameterException ex) { commander.usage(); exitWithError(ex.getMessage(), 1); } if (help) { commander.usage(); exit(0); } }
Example #4
Source File: DispatchSample.java From director-sdk with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { DispatchSample sample = new DispatchSample(); JCommander jc = new JCommander(sample); jc.setProgramName("DispatchSample"); try { jc.parse(args); } catch (ParameterException e) { System.err.println(e.getMessage()); jc.usage(); System.exit(ExitCodes.OK); } System.exit(sample.run()); }
Example #5
Source File: GeoServerSetLayerStyleCommand.java From geowave with Apache License 2.0 | 6 votes |
@Override public String computeResults(final OperationParams params) throws Exception { if (parameters.size() != 1) { throw new ParameterException("Requires argument: <layer name>"); } layerName = parameters.get(0); final Response setLayerStyleResponse = geoserverClient.setLayerStyle(layerName, styleName); if (setLayerStyleResponse.getStatus() == Status.OK.getStatusCode()) { final String style = IOUtils.toString((InputStream) setLayerStyleResponse.getEntity()); return "Set style for GeoServer layer '" + layerName + ": OK" + style; } final String errorMessage = "Error setting style for GeoServer layer '" + layerName + "': " + setLayerStyleResponse.readEntity(String.class) + "\nGeoServer Response Code = " + setLayerStyleResponse.getStatus(); return handleError(setLayerStyleResponse, errorMessage); }
Example #6
Source File: TimeAmountConverter.java From attic-aurora with Apache License 2.0 | 6 votes |
@Override public TimeAmount convert(String raw) { Matcher matcher = AMOUNT_PATTERN.matcher(raw); if (!matcher.matches()) { throw new ParameterException(getErrorString(raw, "must be of the format 1ns, 2secs, etc.")); } Optional<Time> unit = Stream.of(Time.values()) .filter(value -> value.toString().equals(matcher.group(2))) .findFirst(); if (unit.isPresent()) { return new TimeAmount(Long.parseLong(matcher.group(1)), unit.get()); } else { throw new ParameterException( getErrorString(raw, "one of " + ImmutableList.copyOf(Time.values()))); } }
Example #7
Source File: VolumeConverter.java From attic-aurora with Apache License 2.0 | 6 votes |
@Override public Volume convert(String raw) { String[] split = raw.split(":"); if (split.length != 3) { throw new ParameterException( getErrorString(raw, "must be in the format of 'host:container:mode'")); } Mode mode; try { mode = Mode.valueOf(split[2].toUpperCase()); } catch (IllegalArgumentException e) { throw new ParameterException( getErrorString(raw, "Read/Write spec must be in " + Joiner.on(", ").join(Mode.values())), e); } return new Volume(split[1], split[0], mode); }
Example #8
Source File: ListTypesCommand.java From geowave with Apache License 2.0 | 6 votes |
@Override public String computeResults(final OperationParams params) { if (parameters.size() < 1) { throw new ParameterException("Must specify store name"); } final String inputStoreName = parameters.get(0); // Attempt to load store. final File configFile = getGeoWaveConfigFile(params); // Attempt to load input store. final StoreLoader inputStoreLoader = new StoreLoader(inputStoreName); if (!inputStoreLoader.loadFromConfig(configFile, params.getConsole())) { throw new ParameterException("Cannot find store name: " + inputStoreLoader.getStoreName()); } inputStoreOptions = inputStoreLoader.getDataStorePlugin(); final String[] typeNames = inputStoreOptions.createInternalAdapterStore().getTypeNames(); final StringBuffer buffer = new StringBuffer(); for (final String typeName : typeNames) { buffer.append(typeName).append(' '); } return buffer.toString(); }
Example #9
Source File: LcovMergerFlags.java From bazel with Apache License 2.0 | 6 votes |
static LcovMergerFlags parseFlags(String[] args) { LcovMergerFlags flags = new LcovMergerFlags(); JCommander jCommander = new JCommander(flags); jCommander.setAllowParameterOverwriting(true); jCommander.setAcceptUnknownOptions(true); try { jCommander.parse(args); } catch (ParameterException e) { throw new IllegalArgumentException("Error parsing args", e); } if (flags.coverageDir == null && flags.reportsFile == null) { throw new IllegalArgumentException( "At least one of coverage_dir or reports_file should be specified."); } if (flags.coverageDir != null && flags.reportsFile != null) { logger.warning("Overriding --coverage_dir value in favor of --reports_file"); } if (flags.outputFile == null) { throw new IllegalArgumentException("output_file was not specified."); } return flags; }
Example #10
Source File: UPMiner.java From api-mining with GNU General Public License v3.0 | 6 votes |
public static void main(final String[] args) throws Exception { // Runtime parameters final Parameters params = new Parameters(); final JCommander jc = new JCommander(params); try { jc.parse(args); // Mine project System.out.println("Processing " + FilenameUtils.getBaseName(params.arffFile) + "..."); mineAPICallSequences(params.arffFile, params.outFolder, 0.2, 0.2, params.minSupp); } catch (final ParameterException e) { System.out.println(e.getMessage()); jc.usage(); } }
Example #11
Source File: ReportTemplateParameterConverter.java From Strata with Apache License 2.0 | 6 votes |
@Override public ReportTemplate convert(String fileName) { try { File file = new File(fileName); CharSource charSource = ResourceLocator.ofFile(file).getCharSource(); IniFile ini = IniFile.of(charSource); return ReportTemplate.load(ini); } catch (RuntimeException ex) { if (ex.getCause() instanceof FileNotFoundException) { throw new ParameterException(Messages.format("File not found: {}", fileName)); } throw new ParameterException( Messages.format("Invalid report template file: {}" + System.lineSeparator() + "Exception: {}", fileName, ex.getMessage())); } }
Example #12
Source File: SubCommands.java From hugegraph-tools with Apache License 2.0 | 6 votes |
@Override public List<HugeType> convert(String value) { E.checkArgument(value != null && !value.isEmpty(), "HugeType can't be null or empty"); String[] types = value.split(","); if (types.length == 1 && types[0].equalsIgnoreCase("all")) { return ALL_TYPES; } List<HugeType> hugeTypes = new ArrayList<>(); for (String type : types) { try { hugeTypes.add(HugeType.valueOf(type.toUpperCase())); } catch (IllegalArgumentException e) { throw new ParameterException(String.format( "Invalid --type '%s', valid value is 'all' or " + "combination of 'vertex,edge,vertex_label," + "edge_label,property_key,index_label'", type)); } } return hugeTypes; }
Example #13
Source File: ResizeClusterSample.java From director-sdk with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { ResizeClusterSample sample = new ResizeClusterSample(); JCommander jc = new JCommander(sample); jc.setProgramName("ResizeClusterSample"); try { jc.parse(args); } catch (ParameterException e) { System.err.println(e.getMessage()); jc.usage(); System.exit(ExitCodes.PARAMETER_EXCEPTION); } System.exit(sample.run()); }
Example #14
Source File: BaseCommand.java From kafka-helmsman with MIT License | 6 votes |
private List<Map<String, Object>> configuredTopics(Map<String, Object> cmdConfig) { // both 'topicsFile' & 'topics' YAMLs are a list of maps TypeReference<List<Map<String, Object>>> listOfMaps = new TypeReference<List<Map<String, Object>>>() {}; if (cmdConfig.containsKey("topics")) { return MAPPER.convertValue(cmdConfig.get("topics"), listOfMaps); } else { try { return MAPPER.readValue( new FileInputStream((String) cmdConfig.get("topicsFile")), listOfMaps); } catch (IOException e) { throw new ParameterException( "Could not load topics from file " + cmdConfig.get("topicsFile"), e); } } }
Example #15
Source File: PMDCommandLineInterface.java From diff-check with GNU Lesser General Public License v2.1 | 6 votes |
public static PMDParameters extractParameters(PMDParameters arguments, String[] args, String progName) { JCommander jcommander = new JCommander(arguments); jcommander.setProgramName(progName); try { jcommander.parse(args); if (arguments.isHelp()) { jcommander.usage(); System.out.println(buildUsageText(jcommander)); setStatusCodeOrExit(ERROR_STATUS); } } catch (ParameterException e) { jcommander.usage(); System.out.println(buildUsageText(jcommander)); System.err.println(e.getMessage()); setStatusCodeOrExit(ERROR_STATUS); } return arguments; }
Example #16
Source File: GeoServerAddCoverageCommand.java From geowave with Apache License 2.0 | 5 votes |
@Override public String computeResults(final OperationParams params) throws Exception { if (parameters.size() != 1) { throw new ParameterException("Requires argument: <coverage name>"); } if ((workspace == null) || workspace.isEmpty()) { workspace = geoserverClient.getConfig().getWorkspace(); } cvgName = parameters.get(0); final Response addLayerResponse = geoserverClient.addCoverage(workspace, cvgstore, cvgName); if (addLayerResponse.getStatus() == Status.OK.getStatusCode()) { return "Add coverage '" + cvgName + "' to '" + workspace + "/" + cvgstore + "' on GeoServer: OK"; } final String errorMessage = "Error adding GeoServer coverage " + cvgName + ": " + addLayerResponse.readEntity(String.class) + "\nGeoServer Response Code = " + addLayerResponse.getStatus(); return handleError(addLayerResponse, errorMessage); }
Example #17
Source File: CliArgumentsTest.java From gocd-filebased-authentication-plugin with Apache License 2.0 | 5 votes |
@Test public void shouldErrorOutIfRequiredOptionsMissingInCliArguments() throws Exception { thrown.expect(ParameterException.class); thrown.expectMessage("The following option is required: [-u]"); String[] args = {"-p", "badger"}; CliArguments.fromArgs(args); }
Example #18
Source File: DataStoreUtils.java From geowave with Apache License 2.0 | 5 votes |
public static List<Index> loadIndices(final IndexStore indexStore, final String indexNames) { List<Index> loadedIndices = Lists.newArrayList(); // Is there a comma? final String[] indices = indexNames.split(","); for (final String idxName : indices) { Index index = indexStore.getIndex(idxName); if (index == null) { throw new ParameterException("Unable to find index with name: " + idxName); } loadedIndices.add(index); } return Collections.unmodifiableList(loadedIndices); }
Example #19
Source File: AddCassandraStoreCommand.java From geowave with Apache License 2.0 | 5 votes |
@Override public String computeResults(final OperationParams params) throws Exception { final File propFile = getGeoWaveConfigFile(params); final Properties existingProps = ConfigOptions.loadProperties(propFile); // Ensure that a name is chosen. if (parameters.size() != 1) { throw new ParameterException("Must specify store name"); } // Make sure we're not already in the index. final DataStorePluginOptions existingOptions = new DataStorePluginOptions(); if (existingOptions.load(existingProps, getNamespace())) { throw new DuplicateEntryException("That store already exists: " + getPluginName()); } // Save the store options. pluginOptions.save(existingProps, getNamespace()); // Make default? if (Boolean.TRUE.equals(makeDefault)) { existingProps.setProperty(DataStorePluginOptions.DEFAULT_PROPERTY_NAMESPACE, getPluginName()); } // Write properties file ConfigOptions.writeProperties(propFile, existingProps, params.getConsole()); final StringBuilder builder = new StringBuilder(); for (final Object key : existingProps.keySet()) { final String[] split = key.toString().split("\\."); if (split.length > 1) { if (split[1].equals(parameters.get(0))) { builder.append(key.toString() + "=" + existingProps.getProperty(key.toString()) + "\n"); } } } return builder.toString(); }
Example #20
Source File: PositiveLong.java From circus-train with Apache License 2.0 | 5 votes |
@Override public void validate(String name, String value) throws ParameterException { long n = Long.parseLong(value); if (n < 0) { throw new ParameterException("Parameter " + name + " should be positive (found " + value + ")"); } }
Example #21
Source File: FoldSourceFile.java From tassal with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void main(final String[] args) { final Parameters params = new Parameters(); final JCommander jc = new JCommander(params); try { jc.parse(args); foldSourceFile(params.workingDir, params.file, params.project, params.compressionRatio, params.backoffTopic, params.outFile); } catch (final ParameterException e) { System.out.println(e.getMessage()); jc.usage(); } }
Example #22
Source File: PMDParameters.java From diff-check with GNU Lesser General Public License v2.1 | 5 votes |
@Override public Properties convert(String value) { int indexOfSeparator = value.indexOf(SEPARATOR); if (indexOfSeparator < 0) { throw new ParameterException( "Property name must be separated with an = sign from it value: name=value."); } String propertyName = value.substring(0, indexOfSeparator); String propertyValue = value.substring(indexOfSeparator + 1); Properties properties = new Properties(); properties.put(propertyName, propertyValue); return properties; }
Example #23
Source File: ReadStatementsCommand.java From rya with Apache License 2.0 | 5 votes |
@Override public boolean validArguments(final String[] args) { boolean valid = true; try { new JCommander(new KafkaParameters(), args); } catch(final ParameterException e) { valid = false; } return valid; }
Example #24
Source File: PerformanceBenchmark.java From kafka-pubsub-emulator with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException, InterruptedException { LogManager.getLogManager().readConfiguration( PerformanceBenchmark.class.getClassLoader().getResourceAsStream("logging.properties")); PerformanceBenchmark performanceBenchmark = new PerformanceBenchmark(); try { new JCommander(performanceBenchmark, args); performanceBenchmark.execute(); } catch (ParameterException e) { new JCommander(performanceBenchmark).usage(); } }
Example #25
Source File: FoldSourceFileVSMLines.java From tassal with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void main(final String[] args) { final Parameters params = new Parameters(); final JCommander jc = new JCommander(params); try { jc.parse(args); foldSourceFileVSMLines(params.file, params.compressionRatio, params.outFile); } catch (final ParameterException e) { System.out.println(e.getMessage()); jc.usage(); } }
Example #26
Source File: SubCommands.java From hugegraph-tools with Apache License 2.0 | 5 votes |
@Override public void validate(String name, String value) { int retry = Integer.parseInt(value); if (retry <= 0) { throw new ParameterException( "Parameter " + name + " should be positive, " + "but got " + value); } }
Example #27
Source File: KafkaToGeoWaveCommand.java From geowave with Apache License 2.0 | 5 votes |
@Override public Void computeResults(final OperationParams params) throws Exception { final String inputStoreName = parameters.get(0); final String indexList = parameters.get(1); // Config file final File configFile = getGeoWaveConfigFile(params); final StoreLoader inputStoreLoader = new StoreLoader(inputStoreName); if (!inputStoreLoader.loadFromConfig(configFile, params.getConsole())) { throw new ParameterException("Cannot find store name: " + inputStoreLoader.getStoreName()); } inputStoreOptions = inputStoreLoader.getDataStorePlugin(); final IndexStore indexStore = inputStoreOptions.createIndexStore(); inputIndices = DataStoreUtils.loadIndices(indexStore, indexList); // Ingest Plugins final Map<String, GeoWaveAvroFormatPlugin<?, ?>> ingestPlugins = pluginFormats.createAvroPlugins(); // Driver driver = new IngestFromKafkaDriver( inputStoreOptions, inputIndices, ingestPlugins, kafkaOptions, ingestOptions); // Execute if (!driver.runOperation()) { throw new RuntimeException("Ingest failed to execute"); } return null; }
Example #28
Source File: Clean.java From dremio-oss with Apache License 2.0 | 5 votes |
/** * Validates parameter and throws exception if incorrect value or type for param. * Parameter value should be a positive integer * @param name Name of parameter * @param value Value of parameter * @throws ParameterException */ @Override public void validate(String name, String value) throws ParameterException { try { super.validate(name, value); } catch (NumberFormatException | ParameterException e) { throw new ParameterException("Parameter " + name + " should be a positive integer (found " + value +")"); } }
Example #29
Source File: CmdFunctions.java From pulsar with Apache License 2.0 | 5 votes |
@Override void runCmd() throws Exception { // merge deprecated args with new args mergeArgs(); if (StringUtils.isBlank(sourceFile)) { throw new ParameterException("--source-file needs to be specified"); } admin.functions().uploadFunction(sourceFile, path); print("Uploaded successfully"); }
Example #30
Source File: Reverser.java From android-reverse-r with Apache License 2.0 | 5 votes |
/** * Parse command line args into an object. * * @param args raw command line arguments * @return a populated settings object */ private Settings parseCli(String... args) { Settings settings = new Settings(); JCommander commander = new JCommander(settings); try { commander.parse(args); } catch (ParameterException e) { System.err.println(e.getMessage()); commander.usage(); System.exit(0); } return settings; }