diff --git a/dub.sdl b/dub.sdl index 3fa3d95..92e5b27 100644 --- a/dub.sdl +++ b/dub.sdl @@ -3,4 +3,5 @@ description "A minimal D application." authors "tanya" copyright "Copyright © 2025, tanya" license "MPL-2.0" +dependency "commandr" version="~>1.1.0" dependency "taggedalgebraic" version="~>0.11.23" diff --git a/dub.selections.json b/dub.selections.json index 3fbfc12..6b90314 100644 --- a/dub.selections.json +++ b/dub.selections.json @@ -1,6 +1,7 @@ { "fileVersion": 1, "versions": { + "commandr": "1.1.0", "taggedalgebraic": "0.11.23" } } diff --git a/src/main.d b/src/main.d index a3e0fdc..8db13c3 100644 --- a/src/main.d +++ b/src/main.d @@ -3,6 +3,8 @@ import std.file; import std.conv; import std.exception; +import commandr; + import token; import tokentype; import scanner; @@ -44,12 +46,11 @@ void runPrompt(){ } int main(string[] argv){ - if(argv.length > 2){ - writeln("Usage: jlox [script]"); - return 1; - } - if(argv.length == 2) - runFile(argv[1]); + auto args = new Program("lox") + .add(new Argument("path").optional.acceptsFiles) + .parse(argv); + if(args.arg("path")) + runFile(args.arg("path")); else runPrompt(); return 0;