forked from tools/josh
1
0
Fork 0

Implement false, true, and whatis

Fixes #129. Fixes #131.
This commit is contained in:
Florine W. Dekker 2020-06-30 19:09:29 +02:00
parent d078deb545
commit aa8b641f53
Signed by: FWDekker
GPG Key ID: B1B567AF58D6EE0F
3 changed files with 79 additions and 4 deletions

View File

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

View File

@ -507,6 +507,14 @@ return new Command(
\`exit\`,
\`Closes the terminal session.\`,
new InputValidator({maxArgs: 0})
)`,
"false": /* language=JavaScript */ `\
return new Command(
() => {return ExitCode.MISC;},
\`return unsuccessful exit code\`,
\`false\`,
\`Set the <tt>status</tt> environment variable to ${ExitCode.MISC}.\`.trimMultiLines(),
new InputValidator({minArgs: 0})
)`,
"help": /* language=JavaScript */ `\
return new Command(
@ -519,8 +527,8 @@ return new Command(
const command = josh.interpreter.resolve(commandName);
if (command === undefined) {
streams.out.writeLine(\`Unknown command '\${commandName}'.\`);
return ExitCode.COMMAND_NOT_FOUND;
streams.err.writeLine(\`help: Unknown command '\${commandName}'.\`);
return ExitCode.USAGE;
}
let helpString = "<b>Name</b>\\n" + commandName;
@ -945,6 +953,14 @@ return new Command(
\`Update the access and modification times of each <u>file</u> to the current time. If a <u>file</u> does not ${n}
exist, it is created.\`.trimMultiLines(),
new InputValidator({minArgs: 1})
)`,
"true": /* language=JavaScript */ `\
return new Command(
() => {return ExitCode.OK;},
\`return successful exit code\`,
\`true\`,
\`Set the <tt>status</tt> environment variable to ${ExitCode.OK}.\`.trimMultiLines(),
new InputValidator({minArgs: 0})
)`,
"useradd": /* language=JavaScript */ `\
return new Command(
@ -1049,6 +1065,27 @@ return new Command(
\`Modifies the user with the given <u>name</u>. See the "useradd" command for more information on the fields ${n}
that can be modified.\`.trimMultiLines(),
new InputValidator({minArgs: 1, maxArgs: 1})
)`,
"whatis": /* language=JavaScript */ `\
return new Command(
(input, streams) => {
return input.args
.map(commandName => {
const command = josh.interpreter.resolve(commandName);
if (command === undefined) {
streams.err.writeLine(\`whatis: Unknown command '\${commandName}'.\`);
return ExitCode.USAGE;
}
streams.out.writeLine("<b>" + commandName + "</b> - " + command.summary);
return ExitCode.OK;
})
.reduce((acc, exitCode) => exitCode === ExitCode.OK ? acc : exitCode);
},
\`display one-line documentation\`,
\`whatis <u>command</u> <u>...</u>\`,
\`Displays a one-line summary for each <u>command</u>.\`.trimMultiLines(),
new InputValidator({minArgs: 1})
)`,
"whoami": /* language=JavaScript */ `\
return new Command(

View File

@ -324,11 +324,25 @@ describe("commands", () => {
});
});
describe("false", () => {
beforeEach(() => loadCommand("false"));
it("sets the exit code to an erroneous value", () => {
expect(execute("false")).to.not.equal(ExitCode.OK);
});
});
describe("help", () => {
beforeEach(() => loadCommand("help"));
it("outputs something", () => {
it("outputs an error if the command could not be found", () => {
expect(execute("help error")).to.equal(ExitCode.USAGE);
expect(readErr()).to.equal("help: Unknown command 'error'.\n");
});
it("outputs something if the command could be found", () => {
expect(execute("help help")).to.equal(ExitCode.OK);
expect(readOut()).to.not.equal("");
});
@ -722,6 +736,15 @@ describe("commands", () => {
});
});
describe("true", () => {
beforeEach(() => loadCommand("true"));
it("sets the exit code to a successful value", () => {
expect(execute("true")).to.equal(ExitCode.OK);
});
});
describe("useradd", () => {
before(() => HashProvider.default = plainHashProvider);
@ -834,6 +857,21 @@ describe("commands", () => {
});
});
describe("whatis", () => {
beforeEach(() => loadCommand("whatis"));
it("outputs an error if a command could not be found", () => {
expect(execute("whatis error")).to.equal(ExitCode.USAGE);
expect(readErr()).to.equal("whatis: Unknown command 'error'.\n");
});
it("outputs a short summary of itself", () => {
expect(execute("whatis whatis")).to.equal(ExitCode.OK);
expect(readOut()).to.equal("<b>whatis</b> - display one-line documentation\n");
});
});
describe("whoami", () => {
beforeEach(() => loadCommand("whoami"));