-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Validation errors are now aggregated into an output list. Resolves #4 * Output directory is now optional. The tool will only perform validations in this case. Resolves #1 * Path trim error fixed. Resolves #2 * Exception stack traces are now ommitted for validation errors. Resolves #3
- Loading branch information
1 parent
2b2417e
commit 0e6bed9
Showing
9 changed files
with
170 additions
and
36 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ jss-deref-test-* | |
*.o | ||
*.obj | ||
*.lst | ||
js-deref |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,46 @@ | ||
import std.file: getcwd; | ||
import std.file: getcwd, exists; | ||
import std.path: buildPath; | ||
import std.stdio: writeln; | ||
import std.stdio: writefln, writeln, stderr; | ||
|
||
import lib.deref; | ||
import lib.err.valid: ValidationException; | ||
|
||
int main(string[] args) | ||
{ | ||
if (args.length < 2) { | ||
writeln(`js-deref | ||
usage: | ||
js-deref <input-dir> <output-dir>`); | ||
js-deref <input-dir> [output-dir]`); | ||
return 1; | ||
} | ||
|
||
const string cwd = getcwd(); | ||
new Dereferencer(cwd.buildPath(args[1]), cwd.buildPath(args[2])).run(); | ||
|
||
return 0; | ||
Dereferencer deref; | ||
const string inPath = cwd.buildPath(args[1]).trailingSlash(); | ||
|
||
if (!inPath.exists()) { | ||
writefln("Input path does not exist: %s", inPath); | ||
return 1; | ||
} | ||
|
||
if (args.length == 2) { | ||
deref = new Dereferencer(inPath); | ||
} else { | ||
const string outPath = cwd.buildPath(args[2]).trailingSlash(); | ||
deref = new Dereferencer(inPath, outPath); | ||
} | ||
|
||
try { | ||
return deref.run(); | ||
} catch (ValidationException e) { | ||
stderr.writeln(e.msg); | ||
return 1; | ||
} | ||
} | ||
|
||
//TODO: Rehome us | ||
|
||
private string trailingSlash(const string path) { | ||
return path[$-1] == '/' ? path : path ~ '/'; | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module lib.err.json; | ||
|
||
import std.json: JSONException; | ||
import std.string: format; | ||
|
||
import lib.err.valid : ValidationException; | ||
|
||
public class BadJsonException: ValidationException { | ||
public this(const string file, const JSONException e) { | ||
super(format(`%s: | ||
%s`, file, e.msg)); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module lib.err.iref; | ||
|
||
import std.string: format; | ||
|
||
import lib.err.valid: ValidationException; | ||
|
||
public class InvalidRefException : ValidationException { | ||
this(const string path, const string schema) { | ||
super(format("References must be absolute paths to " | ||
~ `the root of the resource directory. Example '/schema/wdk/...'. | ||
Invalid Ref: %s | ||
Schema File: %s`, path, schema)); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module lib.err.nf; | ||
|
||
import std.string: format; | ||
|
||
import lib.err.valid: ValidationException; | ||
|
||
public class NotFoundException : ValidationException { | ||
this(const string path, const string schema) { | ||
super(format(`References not found in the resource directory. | ||
Invalid Ref: %s | ||
Schema File: %s`, path, schema)); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module lib.err.valid; | ||
|
||
import std.exception; | ||
|
||
public class ValidationException : Exception { | ||
public this(const string message) { | ||
super(message); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module lib.err; | ||
|
||
public import lib.err.nf; | ||
public import lib.err.iref; | ||
public import lib.err.valid; | ||
public import lib.err.json; |