net.sourceforge.argparse4j.inf.ArgumentParserException Java Examples
The following examples show how to use
net.sourceforge.argparse4j.inf.ArgumentParserException.
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: Main.java From graphicsfuzz with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { ArgumentParser parser = ArgumentParsers.newArgumentParser("Fuzzer server") .defaultHelp(true); parser.addArgument("--port") .help("Port on which to listen.") .setDefault(8080) .type(Integer.class); try { Namespace ns = parser.parseArgs(args); ShaderJobFileOperations fileOps = new ShaderJobFileOperations(); new FuzzerServer(ns.get("port"), fileOps).start(); } catch (ArgumentParserException ex) { ex.getParser().handleError(ex); } }
Example #2
Source File: UpgradeShadingLanguageVersion.java From graphicsfuzz with Apache License 2.0 | 6 votes |
private static Namespace parse(String[] args) throws ArgumentParserException { ArgumentParser parser = ArgumentParsers.newArgumentParser("UpgradeShadingLanguageVersion") .defaultHelp(true) .description("Upgrade shading language version."); // Required arguments parser.addArgument("shader") .help("Path of shader to be upgraded.") .type(File.class); parser.addArgument("output") .help("Target file name.") .type(String.class); // Optional arguments parser.addArgument("--norename") .help("Do not rename user-defined variables and functions") .action(Arguments.storeTrue()); return parser.parseArgs(args); }
Example #3
Source File: FragmentShaderJobToVertexShaderJob.java From graphicsfuzz with Apache License 2.0 | 6 votes |
private static Namespace parse(String[] args) throws ArgumentParserException { ArgumentParser parser = ArgumentParsers.newArgumentParser("FragmentShaderToShaderJob") .defaultHelp(true) .description("Turns a fragment shader into a shader job with randomized uniforms and " + "(if needed) a suitable vertex shader."); // Required arguments parser.addArgument("shader") .help("Path of .frag shader to be turned into a shader job.") .type(File.class); parser.addArgument("output") .help("Target shader job .json file.") .type(String.class); parser.addArgument("--seed") .help("Seed (unsigned 64 bit long integer) for the random number generator.") .type(String.class); return parser.parseArgs(args); }
Example #4
Source File: GenerateShaderFamilyTest.java From graphicsfuzz with Apache License 2.0 | 6 votes |
private void checkShaderFamilyGeneration(String samplesSubdir, String referenceShaderName, int numVariants, int seed, List<String> extraOptions, ShadingLanguageVersion shadingLanguageVersion) throws ArgumentParserException, InterruptedException, IOException, ReferencePreparationException { final File samplesPrepared = temporaryFolder.newFolder(); final ShaderJobFileOperations fileOperations = new ShaderJobFileOperations(); for (File shaderJobFile : fileOperations.listShaderJobFiles(Paths.get(ToolPaths.getShadersDirectory(),"samples", samplesSubdir).toFile())) { final File newShaderJobFile = new File(samplesPrepared, shaderJobFile.getName()); fileOperations.copyShaderJobFileTo(shaderJobFile, newShaderJobFile, false); maybeAddVertexShaderIfMissing(shadingLanguageVersion, fileOperations, newShaderJobFile); } final String reference = Paths.get(samplesPrepared.getAbsolutePath(), referenceShaderName + ".json").toString(); checkShaderFamilyGeneration(numVariants, seed, extraOptions, reference, samplesPrepared.getAbsolutePath()); }
Example #5
Source File: AdlChecker.java From archie with Apache License 2.0 | 6 votes |
public static void main(String[] args) { ArgumentParser parser = ArgumentParsers.newArgumentParser("AdlChecker") .defaultHelp(true) .description("Checks the syntax of ADL files"); parser.addArgument("file").nargs("*") .help("File to calculate checksum"); Namespace ns = null; try { ns = parser.parseArgs(args); } catch (ArgumentParserException e) { parser.handleError(e); System.exit(1); } if(ns.getList("file").isEmpty()) { parser.printUsage(); parser.printHelp(); } validateArchetypes(ns.getList("file")); }
Example #6
Source File: PredictionApi.java From java-docs-samples with Apache License 2.0 | 6 votes |
public static void argsHelper(String[] args, PrintStream out) throws IOException { ArgumentParser parser = ArgumentParsers.newFor("PredictionApi") .build() .defaultHelp(true) .description("Prediction API Operation"); Subparsers subparsers = parser.addSubparsers().dest("command"); Subparser predictParser = subparsers.addParser("predict"); predictParser.addArgument("modelId"); predictParser.addArgument("filePath"); String projectId = System.getenv("PROJECT_ID"); String computeRegion = System.getenv("REGION_NAME"); Namespace ns = null; try { ns = parser.parseArgs(args); if (ns.get("command").equals("predict")) { predict(projectId, computeRegion, ns.getString("modelId"), ns.getString("filePath")); } } catch (ArgumentParserException e) { parser.handleError(e); } }
Example #7
Source File: ShaderJobFileOperations.java From graphicsfuzz with Apache License 2.0 | 6 votes |
public void getImageDiffStats( ImageData other, JsonObject metrics) throws IOException { metrics.addProperty( "histogramDistance", ImageUtil.compareHistograms(this.histogram, other.histogram)); metrics.addProperty( "psnr", opencv_core.PSNR(this.imageMat, other.imageMat)); FuzzyImageComparison.MainResult fuzzyDiffResult; try { fuzzyDiffResult = FuzzyImageComparison.mainHelper( new String[] {imageFile.toString(), other.imageFile.toString()}); } catch (ArgumentParserException exception) { throw new RuntimeException(exception); } JsonElement fuzzDiffResultJson = new Gson().toJsonTree(fuzzyDiffResult); metrics.add(FUZZY_DIFF_KEY, fuzzDiffResultJson); }
Example #8
Source File: ComparePsnr.java From graphicsfuzz with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws ArgumentParserException, FileNotFoundException { final ArgumentParser parser = ArgumentParsers.newArgumentParser("ComparePsnr") .defaultHelp(true) .description("Print PSNR for two images."); // Required arguments parser.addArgument("image1") .help("Path of first image.") .type(File.class); parser.addArgument("image2") .help("Path of second image.") .type(File.class); final Namespace ns = parser.parseArgs(args); System.out.println(ImageUtil.comparePsnr(ns.get("image1"), ns.get("image2"))); }
Example #9
Source File: Generate.java From graphicsfuzz with Apache License 2.0 | 6 votes |
private static Namespace parse(String[] args) throws ArgumentParserException { ArgumentParser parser = ArgumentParsers.newArgumentParser("Generate") .defaultHelp(true) .description("Generate a shader."); // Required arguments parser.addArgument("reference-json") .help("Input reference shader json file.") .type(File.class); parser.addArgument("donors") .help("Path of folder of donor shaders.") .type(File.class); parser.addArgument("output") .help("Output shader job file file (.json).") .type(File.class); addGeneratorCommonArguments(parser); return parser.parseArgs(args); }
Example #10
Source File: Mutate.java From graphicsfuzz with Apache License 2.0 | 6 votes |
private static Namespace parse(String[] args) throws ArgumentParserException { ArgumentParser parser = ArgumentParsers.newArgumentParser("Mutate") .defaultHelp(true) .description("Takes a shader, gives back a mutated shader."); // Required arguments parser.addArgument("input") .help("A .frag or .vert shader") .type(File.class); parser.addArgument("output") .help("Path of mutated shader.") .type(File.class); parser.addArgument("--seed") .help("Seed (unsigned 64 bit long integer) for the random number generator.") .type(String.class); return parser.parseArgs(args); }
Example #11
Source File: SynthesizeFile.java From java-docs-samples with Apache License 2.0 | 6 votes |
public static void main(String... args) throws Exception { ArgumentParser parser = ArgumentParsers.newFor("SynthesizeFile") .build() .defaultHelp(true) .description("Synthesize a text file or ssml file."); MutuallyExclusiveGroup group = parser.addMutuallyExclusiveGroup().required(true); group.addArgument("--text").help("The text file from which to synthesize speech."); group.addArgument("--ssml").help("The ssml file from which to synthesize speech."); try { Namespace namespace = parser.parseArgs(args); if (namespace.get("text") != null) { synthesizeTextFile(namespace.getString("text")); } else { synthesizeSsmlFile(namespace.getString("ssml")); } } catch (ArgumentParserException e) { parser.handleError(e); } }
Example #12
Source File: PredictionsToInfluxDb.java From seldon-server with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { ArgumentParser parser = ArgumentParsers.newArgumentParser("PredictionsToInfluxDb") .defaultHelp(true) .description("Read Seldon predictions and send stats to influx db"); parser.addArgument("-t", "--topic").setDefault("Predictions").help("Kafka topic to read from"); parser.addArgument("-k", "--kafka").setDefault("localhost:9092").help("Kafka server and port"); parser.addArgument("-z", "--zookeeper").setDefault("localhost:2181").help("Zookeeper server and port"); parser.addArgument("-i", "--influxdb").setDefault("localhost:8086").help("Influxdb server and port"); parser.addArgument("-u", "--influx-user").setDefault("root").help("Influxdb user"); parser.addArgument("-p", "--influx-password").setDefault("root").help("Influxdb password"); parser.addArgument("-d", "--influx-database").setDefault("seldon").help("Influxdb database"); parser.addArgument("--influx-measurement").setDefault("predictions").help("Influxdb Predictions measurement"); Namespace ns = null; try { ns = parser.parseArgs(args); PredictionsToInfluxDb.process(ns); } catch (ArgumentParserException e) { parser.handleError(e); System.exit(1); } }
Example #13
Source File: Main.java From graphicsfuzz with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { ArgumentParser parser = ArgumentParsers.newArgumentParser("Fuzzer server") .defaultHelp(true); parser.addArgument("--port") .help("Port on which to listen.") .setDefault(8080) .type(Integer.class); try { Namespace ns = parser.parseArgs(args); new FuzzerServer(ns.get("port")).start(); } catch (ArgumentParserException ex) { ex.getParser().handleError(ex); } }
Example #14
Source File: PrettyPrint.java From graphicsfuzz with Apache License 2.0 | 6 votes |
private static Namespace parse(String[] args) throws ArgumentParserException { ArgumentParser parser = ArgumentParsers.newArgumentParser("PrettyPrint") .defaultHelp(true) .description("Pretty print a shader."); // Required arguments parser.addArgument("shader") .help("Path of shader to be pretty-printed.") .type(File.class); parser.addArgument("output") .help("Target file name.") .type(String.class); parser.addArgument("--add-braces") .help("Add braces even for single-statement code blocks") .action(Arguments.storeTrue()); return parser.parseArgs(args); }
Example #15
Source File: PrepareReference.java From graphicsfuzz with Apache License 2.0 | 6 votes |
public static void mainHelper(String[] args) throws ArgumentParserException, IOException, ParseTimeoutException, InterruptedException, GlslParserException { Namespace ns = parse(args); ShaderJobFileOperations fileOps = new ShaderJobFileOperations(); prepareReference( ns.get("reference"), ns.get("output"), ns.get("replace_float_literals"), ns.get("max_uniforms"), ns.get("vulkan"), fileOps); }
Example #16
Source File: AbstractBinary.java From rsync4j with GNU General Public License v3.0 | 6 votes |
/** * Sets the commandline options. * * @param options the options to use * @return true if successful * @throws Exception in case of an invalid option */ public boolean setOptions(String[] options) throws Exception { ArgumentParser parser; Namespace ns; parser = getParser(); try { ns = parser.parseArgs(options); } catch (ArgumentParserException e) { parser.handleError(e); return false; } return setOptions(ns); }
Example #17
Source File: GraphicsFuzzServerCommandDispatcher.java From graphicsfuzz with Apache License 2.0 | 6 votes |
@Override public void dispatchCommand(List<String> command, Iface fuzzerServiceManager) throws ShaderDispatchException, ArgumentParserException, InterruptedException, IOException, ParseTimeoutException, GlslParserException { switch (command.get(0)) { case "run_shader_family": RunShaderFamily.mainHelper( command.subList(1, command.size()).toArray(new String[0]), fuzzerServiceManager ); break; case "glsl-reduce": GlslReduce.mainHelper( command.subList(1, command.size()).toArray(new String[0]), fuzzerServiceManager ); break; default: throw new RuntimeException("Unknown command: " + command.get(0)); } }
Example #18
Source File: ImpressionsToInfluxDb.java From seldon-server with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { ArgumentParser parser = ArgumentParsers.newArgumentParser("ImpressionsToInfluxDb") .defaultHelp(true) .description("Read Seldon impressions and send stats to influx db"); parser.addArgument("-t", "--topic").setDefault("impressions").help("Kafka topic to read from"); parser.addArgument("-k", "--kafka").setDefault("localhost:9092").help("Kafka server and port"); parser.addArgument("-z", "--zookeeper").setDefault("localhost:2181").help("Zookeeper server and port"); parser.addArgument("-i", "--influxdb").setDefault("localhost:8086").help("Influxdb server and port"); parser.addArgument("-u", "--influx-user").setDefault("root").help("Influxdb user"); parser.addArgument("-p", "--influx-password").setDefault("root").help("Influxdb password"); parser.addArgument("-d", "--influx-database").setDefault("seldon").help("Influxdb database"); parser.addArgument("--influx-measurement-impressions").setDefault("impressions").help("Influxdb impressions measurement"); parser.addArgument("--influx-measurement-requests").setDefault("requests").help("Influxdb requests measurement"); Namespace ns = null; try { ns = parser.parseArgs(args); ImpressionsToInfluxDb.process(ns); } catch (ArgumentParserException e) { parser.handleError(e); System.exit(1); } }
Example #19
Source File: CliMain.java From styx with Apache License 2.0 | 6 votes |
@Override public void run(ArgumentParser parser, Argument arg, Map<String, Object> attrs, String flag, Object value) throws ArgumentParserException { try { attrs.put(arg.getDest(), ParameterUtil.parseDateHour(value.toString())); } catch (DateTimeParseException dateHourException) { try { attrs.put(arg.getDest(), ParameterUtil.parseDate(value.toString())); } catch (Exception dateException) { throw new ArgumentParserException( String.format( "could not parse date/datehour for parameter '%s'; if datehour: [%s], if date: [%s]", arg.textualName(), dateHourException.getMessage(), dateException.getMessage()), parser); } } }
Example #20
Source File: ComplianceToolModeTest.java From verify-service-provider with MIT License | 5 votes |
@Test public void testThatConfigurationArgumentCanBeParsed() throws ArgumentParserException, JsonProcessingException { ComplianceToolMode complianceToolMode = new ComplianceToolMode(objectMapper, Validators.newValidator(), mock(VerifyServiceProviderApplication.class)); final Subparser subparser = createParser(); complianceToolMode.configure(subparser); String suppliedHost = "127.0.0.1"; String suppliedCallbackUrl = HTTP_LOCALHOST_8080; int suppliedTimeout = 6; MatchingDataset suppliedMatchingDataset = new MatchingDatasetBuilder().build(); int suppliedPort = 0; Namespace namespace = subparser.parseArgs( createArguments( "--url", suppliedCallbackUrl, "-d", objectMapper.writeValueAsString(suppliedMatchingDataset), "--host", suppliedHost, "-p", String.valueOf(suppliedPort), "-t", String.valueOf(suppliedTimeout) ) ); MatchingDataset actual = namespace.get(ComplianceToolMode.IDENTITY_DATASET); assertThat(actual).isEqualToComparingFieldByFieldRecursively(suppliedMatchingDataset); String url = namespace.get(ComplianceToolMode.ASSERTION_CONSUMER_URL); assertThat(url).isEqualTo(suppliedCallbackUrl); Integer timeout = namespace.get(ComplianceToolMode.TIMEOUT); assertThat(timeout).isEqualTo(suppliedTimeout); Integer port = namespace.get(ComplianceToolMode.PORT); assertThat(port).isEqualTo(suppliedPort); String host = namespace.get(ComplianceToolMode.BIND_HOST); assertThat(host).isEqualTo(suppliedHost); }
Example #21
Source File: OutputFolderArgumentType.java From RepoSense with MIT License | 5 votes |
@Override public Path convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { // Piggyback on library methods to do file existence checks Arguments.fileType().verifyExists().verifyIsDirectory().verifyCanWrite() .or() .verifyNotExists().convert(parser, arg, value); return Paths.get(value).resolve(ArgsParser.DEFAULT_REPORT_NAME); }
Example #22
Source File: ZoneIdArgumentType.java From RepoSense with MIT License | 5 votes |
@Override public ZoneId convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { try { return ZoneId.of(value); } catch (DateTimeException dte) { throw new ArgumentParserException(MESSAGE_TIMEZONE_INVALID, parser); } }
Example #23
Source File: AlphanumericArgumentType.java From RepoSense with MIT License | 5 votes |
@Override public String convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { if (!ALPHANUMERIC_PATTERN.matcher(value).matches()) { throw new ArgumentParserException( String.format(PARSE_EXCEPTION_MESSAGE_NOT_IN_ALPLANUMERIC, value), parser); } return value; }
Example #24
Source File: ItemSimilarityProcessor.java From seldon-server with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { ArgumentParser parser = ArgumentParsers.newArgumentParser("ImpressionsToInfluxDb") .defaultHelp(true) .description("Read Seldon impressions and send stats to influx db"); parser.addArgument("-t", "--topic").setDefault("actions").help("Kafka topic to read from"); parser.addArgument("-c", "--client").required(true).help("Client to run item similarity"); parser.addArgument("-o", "--output-topic").required(true).help("Output topic"); parser.addArgument("-k", "--kafka").setDefault("localhost:9092").help("Kafka server and port"); parser.addArgument("-z", "--zookeeper").setDefault("localhost:2181").help("Zookeeper server and port"); parser.addArgument("-w", "--window-secs").type(Integer.class).setDefault(3600*5).help("streaming window size in secs, -1 means ignore"); parser.addArgument("-u", "--window-processed").type(Integer.class).setDefault(-1).help("streaming window size in processed count, -1 means ignore"); parser.addArgument("--output-poll-secs").type(Integer.class).setDefault(60).help("output timer polling period in secs"); parser.addArgument("--hashes").type(Integer.class).setDefault(100).help("number of hashes"); parser.addArgument("-m", "--min-activity").type(Integer.class).setDefault(200).help("min activity"); parser.addArgument("-p", "--parse-date-method").choices("json-time","json-utc","system").setDefault("json-time").help("min activity"); Namespace ns = null; try { ns = parser.parseArgs(args); ItemSimilarityProcessor processor = new ItemSimilarityProcessor(ns); processor.process(ns); } catch (ArgumentParserException e) { parser.handleError(e); System.exit(1); } }
Example #25
Source File: ConfigFolderArgumentType.java From RepoSense with MIT License | 5 votes |
@Override public Path convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { // Piggyback on library methods to do file existence checks Arguments.fileType().verifyExists().verifyIsDirectory().verifyCanRead().convert(parser, arg, value); if (Files.exists(Paths.get(value).resolve(RepoConfigCsvParser.REPO_CONFIG_FILENAME))) { return Paths.get(value); } throw new ArgumentParserException(String.format(PARSE_EXCEPTION_MESSAGE_MISSING_REQUIRED_CONFIG_FILES, RepoConfigCsvParser.REPO_CONFIG_FILENAME), parser); }
Example #26
Source File: IdentityDatasetArgumentResolver.java From verify-service-provider with MIT License | 5 votes |
@Override public MatchingDataset convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { try { return resolveMatchingDataset(value); } catch (IOException | MatchingDatasetArgumentValidationError e) { throw new ArgumentParserException(e.getMessage(), e, parser); } }
Example #27
Source File: SimpleConsumer.java From kafka-examples with Apache License 2.0 | 5 votes |
public static void main(String[] args) { ArgumentParser parser = argParser(); try { Namespace result = parser.parseArgs(args); Properties configs = getConsumerConfigs(result); List<TopicPartition> partitions = getPartitions(result.getString("topic.partitions")); final SimpleConsumer<Serializable, Serializable> consumer = new SimpleConsumer<>(configs, partitions); consumer.run(); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { consumer.close(); } })); } catch (ArgumentParserException e) { if(args.length == 0) parser.printHelp(); else parser.handleError(e); System.exit(0); } }
Example #28
Source File: CheckColorComponents.java From graphicsfuzz with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws ArgumentParserException, IOException { final ArgumentParser parser = ArgumentParsers.newArgumentParser("CheckColorComponents") .defaultHelp(true) .description("Exits with code 0 if and only if the given image uses only the given color " + "components as the RGBA values of its pixels."); // Required arguments parser.addArgument("image") .help("Path to PNG image") .type(File.class); parser.addArgument("components") .type(Integer.class) .nargs("+") .help("Allowed components, each in range 0..255."); final Namespace ns = parser.parseArgs(args); final File image = ns.get("image"); final List<Integer> components = ns.get("components"); if (components.stream().anyMatch(item -> item < 0 || item > 255)) { System.err.println("Error: given component list " + components + " includes elements not " + "in range 0..255."); } if (!ImageColorComponents.containsOnlyGivenComponentValues(ImageIO.read(image), components)) { System.exit(1); } }
Example #29
Source File: ModelApi.java From java-docs-samples with Apache License 2.0 | 5 votes |
static void argsHelper(String[] args) { ArgumentParser parser = ArgumentParsers.newFor("ModelApi") .build() .defaultHelp(true) .description("Model API operations."); Subparsers subparsers = parser.addSubparsers().dest("command"); Subparser createModelParser = subparsers.addParser("create_model"); createModelParser.addArgument("datasetId"); createModelParser.addArgument("modelName"); createModelParser.addArgument("trainBudget"); String projectId = System.getenv("GOOGLE_CLOUD_PROJECT"); String computeRegion = System.getenv("REGION_NAME"); if (projectId == null || computeRegion == null) { System.out.println("Set `GOOGLE_CLOUD_PROJECT` and `REGION_NAME` as specified in the README"); System.exit(-1); } try { Namespace ns = parser.parseArgs(args); if (ns.get("command").equals("create_model")) { createModel( projectId, computeRegion, ns.getString("datasetId"), ns.getString("modelName"), ns.getString("trainBudget")); } } catch (ArgumentParserException e) { parser.handleError(e); } }
Example #30
Source File: RunShaderFamily.java From graphicsfuzz with Apache License 2.0 | 5 votes |
public static void main(String[] args) { try { mainHelper(args, null); } catch (ArgumentParserException exception) { exception.getParser().handleError(exception); System.exit(1); } catch (Exception ex) { ex.printStackTrace(); System.exit(1); } }