Add status code argument to exit command

Fixes #144.
This commit is contained in:
Florine W. Dekker 2020-12-07 11:34:48 +01:00
parent 17e8ab37a0
commit 46400c0689
Signed by: FWDekker
GPG Key ID: B1B567AF58D6EE0F
3 changed files with 18 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "fwdekker.com", "name": "fwdekker.com",
"version": "0.39.0", "version": "0.39.1",
"description": "The source code of [my personal website](https://fwdekker.com/).", "description": "The source code of [my personal website](https://fwdekker.com/).",
"author": "Felix W. Dekker", "author": "Felix W. Dekker",
"browser": "dist/bundle.js", "browser": "dist/bundle.js",

View File

@ -535,12 +535,12 @@ return new Command(
return new Command( return new Command(
(input, streams) => { (input, streams) => {
josh.environment.set("user", ""); josh.environment.set("user", "");
return ExitCode.OK; return parseInt(input.args[0] || "0");
}, },
\`close session\`, \`close session\`,
\`exit\`, \`exit\`,
\`Closes the terminal session.\`, \`Closes the terminal session.\`,
new InputValidator({maxArgs: 0}) new InputValidator({minArgs: 0, maxArgs: 1})
)`, )`,
"false": /* language=JavaScript */ `\ "false": /* language=JavaScript */ `\
return new Command( return new Command(

View File

@ -360,10 +360,24 @@ describe("commands", () => {
beforeEach(() => loadCommand("exit")); beforeEach(() => loadCommand("exit"));
it("changes the current user", () => { it("removes the current user", () => {
environment.set("user", "wish");
expect(execute("exit")).to.equal(ExitCode.OK); expect(execute("exit")).to.equal(ExitCode.OK);
expect(environment.get("user")).to.equal(""); expect(environment.get("user")).to.equal("");
}); });
it("has exit code of OK by default", () => {
environment.set("status", "9");
expect(execute("exit")).to.equal(ExitCode.OK);
});
it("returns the user-supplied exit code", () => {
environment.set("status", "1");
expect(execute("exit 46")).to.equal(46);
});
}); });
describe("false", () => { describe("false", () => {