Added --cmd

This commit is contained in:
nazrin 2025-06-02 01:44:08 +00:00
parent e9e3c992cb
commit 4776b84310

View file

@ -80,10 +80,17 @@ static class Lox{
int main(string[] argv){
auto args = new Program("lox")
.add(new Argument("path").optional.acceptsFiles)
.add(new Option("cmd").name("command"))
.parse(argv);
try{
if(args.arg("path"))
Lox.runFile(args.arg("path"));
if(args.arg("path") && args.option("command")){
stderr.writeln("Cant have both path and --cmd");
return 3;
}
if(auto cmd = args.option("command"))
Lox.run(cmd);
else if(auto path = args.arg("path"))
Lox.runFile(path);
else
Lox.runPrompt();
} catch(MainException rte){