Skip to content

Commit

Permalink
Accept multiple values provided with single "-s"/"--source" argument
Browse files Browse the repository at this point in the history
  • Loading branch information
unkish authored and joelittlejohn committed Jan 21, 2023
1 parent 5c28f84 commit 648eb80
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class Arguments implements GenerationConfig {
@Parameter(names = { "-t", "--target" }, description = "The target directory into which generated types will be written", required = true)
private File targetDirectory;

@Parameter(names = { "-s", "--source" }, description = "The source file(s) or directory(ies) from which JSON Schema will be read", required = true, converter = UrlConverter.class)
@Parameter(names = { "-s", "--source" }, description = "The source file(s) or directory(ies) from which JSON Schema will be read", required = true, variableArity = true, converter = UrlConverter.class)
private List<URL> sourcePaths;

@Parameter(names = { "-b", "--generate-builders" }, description = "Generate builder-style methods as well as setters")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Iterator;

import org.jsonschema2pojo.InclusionLevel;
import org.junit.After;
Expand Down Expand Up @@ -151,6 +153,46 @@ public void requestingVersionCausesVersion() {
assertThat(new String(systemOutCapture.toByteArray(), StandardCharsets.UTF_8).matches("(?s)jsonschema2pojo version \\d.*"), is(true));
}

@Test
public void parseRecognisesSourceWithMultipleValues() {
ArgsForTest args = (ArgsForTest) new ArgsForTest().parse(new String[] {
"-s", "/home/source", "/home/second_source", "-t", "/home/target"
});

assertThat(args.didExit(), is(false));
final Iterator<URL> sources = args.getSource();
assertThat(sources.next().getFile(), endsWith("/home/source"));
assertThat(sources.next().getFile(), endsWith("/home/second_source"));
assertThat(sources.hasNext(), is(false));
}

@Test
public void parseRecognisesMultipleSources() {
ArgsForTest args = (ArgsForTest) new ArgsForTest().parse(new String[] {
"-s", "/home/source", "-s", "/home/second_source", "-t", "/home/target"
});

assertThat(args.didExit(), is(false));
final Iterator<URL> sources = args.getSource();
assertThat(sources.next().getFile(), endsWith("/home/source"));
assertThat(sources.next().getFile(), endsWith("/home/second_source"));
assertThat(sources.hasNext(), is(false));
}

@Test
public void parseRecognisesMultipleSourcesWithMultipleValues() {
ArgsForTest args = (ArgsForTest) new ArgsForTest().parse(new String[] {
"-s", "/home/source", "/home/second_source", "-s", "/home/third_source", "-t", "/home/target"
});

assertThat(args.didExit(), is(false));
final Iterator<URL> sources = args.getSource();
assertThat(sources.next().getFile(), endsWith("/home/source"));
assertThat(sources.next().getFile(), endsWith("/home/second_source"));
assertThat(sources.next().getFile(), endsWith("/home/third_source"));
assertThat(sources.hasNext(), is(false));
}

private File theFile(String path) {
return new File(path);
}
Expand Down

0 comments on commit 648eb80

Please sign in to comment.