Created
August 25, 2014 16:34
-
-
Save bdkosher/2d423dc3f3e65e3dee78 to your computer and use it in GitHub Desktop.
Pattern for assigning and transforming String args to target File type, plus validating their existence--all in one compact piece of code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def (f1, f2) = [new File(args[0]), new File(args[1])].each { f -> | |
if (!f.exists() || f.isDirectory()) { | |
println "$f does not exist or is a directory" | |
System.exit(0); | |
} else { | |
f | |
} | |
} | |
println "$f1 and $f2 provided" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO: Generalize this code to deal with type conversion, validation, and expected number of arguments. Instead of exiting upon validation failure, we could return a processed argument back that represents the specific error.