add cwd command line arg

This commit is contained in:
2025-05-18 08:56:25 -05:00
parent 708a112449
commit bf2336a172
2 changed files with 17 additions and 3 deletions

View File

@@ -2,6 +2,6 @@ Thank you for using Prosperon!
Provided are prosperon builds for all available platforms. Simply run prosperon for your platform in a game folder to play!
To get started, take a dive into the provided example games in the examples folder. Just copy the prosperon executable for your platform, into any provided example folder, then run it!
To get started, take a dive into the provided example games in the examples folder. You can either copy the prosperon executable into an example directory and run it there, or run `prosperon path/to/example` from the project root.
You can take a look through the docs folder for the prosperon manual to learn all about it. The manual is available on the web at [docs.prosperon.dev](https://docs.prosperon.dev).

View File

@@ -163,6 +163,9 @@ Cmdline.register_order(
"spawn",
function(argv) {
prosperon.args = parse_args(argv)
if (!prosperon.args.cwd) prosperon.args.cwd = '.'
io.mount(prosperon.args.cwd)
if (!prosperon.args.program)
os.exit()
},
@@ -214,8 +217,19 @@ function cmd_args(cmds) {
cmds.unshift("--program");
cmds.unshift("spawn");
} else if (!Cmdline.orders[cmds[0]]) {
// If the first token isn't a recognized command, treat it as a script
cmds.unshift("--program");
// If the first token isn't a recognized command, treat it as either
// a directory containing main.js, or a script to run directly.
var arg0 = cmds.shift();
if (io.is_directory(arg0)) {
var script = cmds[0] ? cmds.shift() : "main.js";
cmds.unshift(script);
cmds.unshift("--program");
cmds.unshift(arg0);
cmds.unshift("--cwd");
} else {
cmds.unshift(arg0);
cmds.unshift("--program");
}
cmds.unshift("spawn");
}