mirror of
https://github.com/zaaarf/lillero-mapping-writer.git
synced 2024-11-22 20:54:50 +01:00
feat: -o flag
This commit is contained in:
parent
3e2f0a6bcf
commit
32ea510f10
1 changed files with 7 additions and 4 deletions
|
@ -23,7 +23,8 @@ public class MappingWriter {
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) throws IOException, ParseException {
|
public static void main(String[] args) throws IOException, ParseException {
|
||||||
Options options = new Options()
|
Options options = new Options()
|
||||||
.addOption("r", "reverse", false, "Writes down inverted mappings");
|
.addOption("r", "reverse", false, "Writes down inverted mappings")
|
||||||
|
.addOption("o", "overwrite", false, "Overwrites the file even if it exists");
|
||||||
DefaultParser parser = new DefaultParser();
|
DefaultParser parser = new DefaultParser();
|
||||||
CommandLine cmdLine = parser.parse(options, args);
|
CommandLine cmdLine = parser.parse(options, args);
|
||||||
args = cmdLine.getArgs();
|
args = cmdLine.getArgs();
|
||||||
|
@ -70,10 +71,12 @@ public class MappingWriter {
|
||||||
//now for the file
|
//now for the file
|
||||||
File targetFile = new File(args[2]);
|
File targetFile = new File(args[2]);
|
||||||
|
|
||||||
|
if(!cmdLine.hasOption("overwrite") || !targetFile.exists()) {
|
||||||
if(!targetFile.createNewFile()) {
|
if(!targetFile.createNewFile()) {
|
||||||
System.err.println("File already exists!");
|
System.err.println("File already exists!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(!targetFile.canWrite()) {
|
if(!targetFile.canWrite()) {
|
||||||
System.err.println("Failed to write to file: access denied.");
|
System.err.println("Failed to write to file: access denied.");
|
||||||
|
|
Loading…
Reference in a new issue