Skip to content

Commit

Permalink
Add option to run internal scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
aNNiMON committed Feb 17, 2024
1 parent b511d57 commit c899609
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ownlang-desktop/src/main/java/com/annimon/ownlang/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ public static void main(String[] args) throws IOException {
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];
Expand Down Expand Up @@ -124,6 +135,7 @@ private static void printUsage() {
-a, --showast Show AST of program
-t, --showtokens Show lexical tokens
-m, --showtime Show elapsed time of parsing and execution
ownlang run <scriptName>
""");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

public class RunOptions {
private static final String DEFAULT_PROGRAM = "program.own";
private static final String RES_SCRIPTS = "/scripts/";

// input
String programPath;
Expand All @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions ownlang-desktop/src/main/resources/scripts/listscripts.own
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
println "Available scripts:
checkUpdate - checks updates on GitHub
To run a script use command:
ownlang run checkUpdate
"

0 comments on commit c899609

Please sign in to comment.