Skip to content

Commit

Permalink
Added option to create output directories as needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Aklakan committed Feb 23, 2024
1 parent 5e85952 commit 8da7f56
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ public static class OutputSpec {
@Option(names = { "--out-format", "--of" }, description = "Output format")
public String outFormat = null;

@Option(names = { "--out-mkdirs" }, description = "Create directories to the output file as needed.")
public boolean outMkDirs = false;

// Subsume jq stuff under -w jq ?

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ public static int sparqlIntegrate(CmdSparqlIntegrateMain cmd) throws Exception {
OutputStream operationalOut;
if (!Strings.isNullOrEmpty(outFilename)) {
outFile = Paths.get(outFilename).toAbsolutePath();

Path outDir = outFile.getParent();
if (cmd.outMkDirs && outDir != null) {
Files.createDirectories(outDir);
}

if(Files.exists(outFile) && !Files.isWritable(outFile)) {
throw new RuntimeException("Cannot write to specified output file: " + outFile.toAbsolutePath());
}
Expand Down

0 comments on commit 8da7f56

Please sign in to comment.