@Test public void testParseInputs_defaultValues() { ArgsParserWithDefaultValues parser = new ArgsParserWithDefaultValues( ImmutableMap.<String, String>builder() .put("i", "1") .put("f", "2.0") .put("s", "3") .put("b", "true") .put("t", LocalDateTime.ofInstant(Instant.EPOCH, ZoneOffset.UTC).toString()) .put("d", "P1D") .build()); ImmutableMap<String, Literal> expected = ImmutableMap.<String, Literal>builder() .put("i", literalOf(Primitive.ofInteger(1))) .put("f", literalOf(Primitive.ofFloat(2.0))) .put("s", literalOf(Primitive.ofString("3"))) .put("b", literalOf(Primitive.ofBoolean(true))) .put("t", literalOf(Primitive.ofDatetime(Instant.EPOCH))) .put("d", literalOf(Primitive.ofDuration(Duration.ofDays(1)))) .build(); Map<String, Literal> inputs = parser.parseInputs( "jflyte", ImmutableMap.<String, Variable>builder() .put("i", createVar(SimpleType.INTEGER)) .put("f", createVar(SimpleType.FLOAT)) .put("s", createVar(SimpleType.STRING)) .put("b", createVar(SimpleType.BOOLEAN)) .put("t", createVar(SimpleType.DATETIME)) .put("d", createVar(SimpleType.DURATION)) .build(), ImmutableList.of()); assertEquals(expected, inputs); }
public Map<String, Literal> parseInputs( String synopsis, Map<String, Variable> variableMap, List<String> inputArgs) { CommandLine.Model.CommandSpec spec = CommandLine.Model.CommandSpec.create(); spec.usageMessage().customSynopsis(synopsis); variableMap.forEach((name, variable) -> spec.addOption(getOption(name, variable))); CommandLine.ParseResult result = new CommandLine(spec).parseArgs(inputArgs.toArray(new String[0])); return variableMap.entrySet().stream() .map( kv -> { String name = kv.getKey(); Literal defaultValue = getDefaultValueAsLiteral(name, kv.getValue()); return Maps.immutableEntry(name, result.matchedOptionValue(name, defaultValue)); }) .collect(toMap(Map.Entry::getKey, Map.Entry::getValue)); }
ExecuteLocalArgsParser { public Map<String, Literal> parseInputs( String synopsis, Map<String, Variable> variableMap, List<String> inputArgs) { CommandLine.Model.CommandSpec spec = CommandLine.Model.CommandSpec.create(); spec.usageMessage().customSynopsis(synopsis); variableMap.forEach((name, variable) -> spec.addOption(getOption(name, variable))); CommandLine.ParseResult result = new CommandLine(spec).parseArgs(inputArgs.toArray(new String[0])); return variableMap.entrySet().stream() .map( kv -> { String name = kv.getKey(); Literal defaultValue = getDefaultValueAsLiteral(name, kv.getValue()); return Maps.immutableEntry(name, result.matchedOptionValue(name, defaultValue)); }) .collect(toMap(Map.Entry::getKey, Map.Entry::getValue)); } }
ExecuteLocalArgsParser { public Map<String, Literal> parseInputs( String synopsis, Map<String, Variable> variableMap, List<String> inputArgs) { CommandLine.Model.CommandSpec spec = CommandLine.Model.CommandSpec.create(); spec.usageMessage().customSynopsis(synopsis); variableMap.forEach((name, variable) -> spec.addOption(getOption(name, variable))); CommandLine.ParseResult result = new CommandLine(spec).parseArgs(inputArgs.toArray(new String[0])); return variableMap.entrySet().stream() .map( kv -> { String name = kv.getKey(); Literal defaultValue = getDefaultValueAsLiteral(name, kv.getValue()); return Maps.immutableEntry(name, result.matchedOptionValue(name, defaultValue)); }) .collect(toMap(Map.Entry::getKey, Map.Entry::getValue)); }  }
ExecuteLocalArgsParser { public Map<String, Literal> parseInputs( String synopsis, Map<String, Variable> variableMap, List<String> inputArgs) { CommandLine.Model.CommandSpec spec = CommandLine.Model.CommandSpec.create(); spec.usageMessage().customSynopsis(synopsis); variableMap.forEach((name, variable) -> spec.addOption(getOption(name, variable))); CommandLine.ParseResult result = new CommandLine(spec).parseArgs(inputArgs.toArray(new String[0])); return variableMap.entrySet().stream() .map( kv -> { String name = kv.getKey(); Literal defaultValue = getDefaultValueAsLiteral(name, kv.getValue()); return Maps.immutableEntry(name, result.matchedOptionValue(name, defaultValue)); }) .collect(toMap(Map.Entry::getKey, Map.Entry::getValue)); }  Map<String, Literal> parseInputs(
      String synopsis, Map<String, Variable> variableMap, List<String> inputArgs); }
ExecuteLocalArgsParser { public Map<String, Literal> parseInputs( String synopsis, Map<String, Variable> variableMap, List<String> inputArgs) { CommandLine.Model.CommandSpec spec = CommandLine.Model.CommandSpec.create(); spec.usageMessage().customSynopsis(synopsis); variableMap.forEach((name, variable) -> spec.addOption(getOption(name, variable))); CommandLine.ParseResult result = new CommandLine(spec).parseArgs(inputArgs.toArray(new String[0])); return variableMap.entrySet().stream() .map( kv -> { String name = kv.getKey(); Literal defaultValue = getDefaultValueAsLiteral(name, kv.getValue()); return Maps.immutableEntry(name, result.matchedOptionValue(name, defaultValue)); }) .collect(toMap(Map.Entry::getKey, Map.Entry::getValue)); }  Map<String, Literal> parseInputs(
      String synopsis, Map<String, Variable> variableMap, List<String> inputArgs);  }