Skip to content

Commit c899609

Browse files
committed
Add option to run internal scripts
1 parent b511d57 commit c899609

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

ownlang-desktop/src/main/java/com/annimon/ownlang/Main.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ public static void main(String[] args) throws IOException {
9494
Sandbox.main(createOwnLangArgs(args, i + 1));
9595
return;
9696

97+
case "run":
98+
final String scriptName;
99+
if (i + 1 < args.length) {
100+
scriptName = args[i + 1];
101+
createOwnLangArgs(args, i + 2);
102+
} else {
103+
scriptName = "listScripts";
104+
}
105+
run(RunOptions.script(scriptName));
106+
return;
107+
97108
default:
98109
if (options.programSource == null) {
99110
options.programSource = args[i];
@@ -124,6 +135,7 @@ private static void printUsage() {
124135
-a, --showast Show AST of program
125136
-t, --showtokens Show lexical tokens
126137
-m, --showtime Show elapsed time of parsing and execution
138+
ownlang run <scriptName>
127139
""");
128140
}
129141

ownlang-desktop/src/main/java/com/annimon/ownlang/RunOptions.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
public class RunOptions {
88
private static final String DEFAULT_PROGRAM = "program.own";
9+
private static final String RES_SCRIPTS = "/scripts/";
910

1011
// input
1112
String programPath;
@@ -21,6 +22,13 @@ public class RunOptions {
2122

2223
private final InputSourceDetector inputSourceDetector = new InputSourceDetector();
2324

25+
static RunOptions script(String name) {
26+
final var options = new RunOptions();
27+
options.programPath = InputSourceDetector.RESOURCE_PREFIX
28+
+ RES_SCRIPTS + name.toLowerCase() + ".own";
29+
return options;
30+
}
31+
2432
boolean linterEnabled() {
2533
return lintMode != null && lintMode != LinterStage.Mode.NONE;
2634
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
println "Available scripts:
2+
checkUpdate - checks updates on GitHub
3+
4+
To run a script use command:
5+
ownlang run checkUpdate
6+
"

0 commit comments

Comments
 (0)