Skip to content

Commit

Permalink
add option -w to prevent overwriting all the time
Browse files Browse the repository at this point in the history
  • Loading branch information
edmonl committed Feb 7, 2015
1 parent 9b51820 commit 60ca7b1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main/java/org/ruleml/translation/ruleml2tptp/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import org.kohsuke.args4j.Option;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringReader;
import java.io.StringWriter;
Expand Down Expand Up @@ -52,6 +52,9 @@ public class Main {
@Option(name="-f",aliases={"-transformer-factory"},metaVar="<class>",usage="use given factory class")
private String transFactoryClass;

@Option(name="-w",aliases={"-overwrite"},usage="overwrite the output file")
private boolean overwrite;

@Option(name="-r",aliases={"-recursive"},hidden=true,usage="traverse the directory tree for input files")
private boolean recursive;

Expand Down Expand Up @@ -106,6 +109,10 @@ private void run() {
final Translator translator = new Translator(transFactory);
translator.loadTemplates();
try {
if (output != null && !overwrite && !output.createNewFile()) {
System.err.println("The output file has existed. Use option \"-w\" to overwrite it.");
System.exit(EC_GENERAL);
}
if (input == null) {
if (output == null) {
translate(translator, System.in, System.out);
Expand All @@ -122,7 +129,7 @@ private void run() {
System.err.println(ex.getMessageAndLocation());
System.err.println();
System.exit(EC_TRANSFORM);
} catch (FileNotFoundException ex) {
} catch (IOException ex) {
System.err.println("Failed to operate file: " + ex.getLocalizedMessage());
System.err.println();
System.exit(EC_TRANSFORM);
Expand Down

0 comments on commit 60ca7b1

Please sign in to comment.