mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 00:34:20 +03:00
Add option to run internal scripts
This commit is contained in:
parent
b511d57940
commit
c8996095b2
@ -94,6 +94,17 @@ public final class Main {
|
||||
Sandbox.main(createOwnLangArgs(args, i + 1));
|
||||
return;
|
||||
|
||||
case "run":
|
||||
final String scriptName;
|
||||
if (i + 1 < args.length) {
|
||||
scriptName = args[i + 1];
|
||||
createOwnLangArgs(args, i + 2);
|
||||
} else {
|
||||
scriptName = "listScripts";
|
||||
}
|
||||
run(RunOptions.script(scriptName));
|
||||
return;
|
||||
|
||||
default:
|
||||
if (options.programSource == null) {
|
||||
options.programSource = args[i];
|
||||
@ -124,6 +135,7 @@ public final class Main {
|
||||
-a, --showast Show AST of program
|
||||
-t, --showtokens Show lexical tokens
|
||||
-m, --showtime Show elapsed time of parsing and execution
|
||||
ownlang run <scriptName>
|
||||
""");
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import static com.annimon.ownlang.util.input.InputSourceDetector.RESOURCE_PREFIX
|
||||
|
||||
public class RunOptions {
|
||||
private static final String DEFAULT_PROGRAM = "program.own";
|
||||
private static final String RES_SCRIPTS = "/scripts/";
|
||||
|
||||
// input
|
||||
String programPath;
|
||||
@ -21,6 +22,13 @@ public class RunOptions {
|
||||
|
||||
private final InputSourceDetector inputSourceDetector = new InputSourceDetector();
|
||||
|
||||
static RunOptions script(String name) {
|
||||
final var options = new RunOptions();
|
||||
options.programPath = InputSourceDetector.RESOURCE_PREFIX
|
||||
+ RES_SCRIPTS + name.toLowerCase() + ".own";
|
||||
return options;
|
||||
}
|
||||
|
||||
boolean linterEnabled() {
|
||||
return lintMode != null && lintMode != LinterStage.Mode.NONE;
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
println "Available scripts:
|
||||
checkUpdate - checks updates on GitHub
|
||||
|
||||
To run a script use command:
|
||||
ownlang run checkUpdate
|
||||
"
|
Loading…
Reference in New Issue
Block a user