Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to specify the output file name on the command line. #27

Merged
merged 1 commit into from
Apr 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ Example of Maven integration:
<arguments>
<argument>-cf</argument>
<argument>my-config.json</argument>
<argument>--outputFile</argument>
<argument>${basedir}/src/main/webapp/validation/validation.json</argument>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public static void main(String[] args) {
private static Options loadOptions(CommandLine cli) {
InputStream inputStream = null;
String configFile = cli.getOptionValue("cf");
String outputFile = cli.getOptionValue("outputFile");

try {
if (StringUtils.isEmpty(configFile)) {
Expand All @@ -72,7 +73,11 @@ private static Options loadOptions(CommandLine cli) {
System.out.println("Building parser configuration from configured file path '" + configFile + "'.");
inputStream = new FileInputStream(new File(configFile));
}
return new ObjectMapper().readValue(inputStream, Options.class);
Options opt = new ObjectMapper().readValue(inputStream, Options.class);
if (StringUtils.isEmpty(opt.getOutputFile())) {
opt.setOutputFile(outputFile);
}
return opt;
} catch (IOException e) {
throw new IllegalArgumentException("Cannot read config file.", e);
} finally {
Expand Down Expand Up @@ -110,6 +115,8 @@ private static org.apache.commons.cli.Options createCliOptions() {
org.apache.commons.cli.Options options = new org.apache.commons.cli.Options();
options.addOption(new Option("cf", true,
"path to JSON config file, if omitted valdr-bean-validation.json is " + "expected at root of class path"));
options.addOption(new Option("outputFile", true,
"path to output file, which will be used, if no outputFile is specified in the JSON config"));
return options;
}

Expand Down