forked from tools/josh
parent
d078deb545
commit
aa8b641f53
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "fwdekker.com",
|
"name": "fwdekker.com",
|
||||||
"version": "0.35.0",
|
"version": "0.36.0",
|
||||||
"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",
|
||||||
|
|
|
@ -507,6 +507,14 @@ return new Command(
|
||||||
\`exit\`,
|
\`exit\`,
|
||||||
\`Closes the terminal session.\`,
|
\`Closes the terminal session.\`,
|
||||||
new InputValidator({maxArgs: 0})
|
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 */ `\
|
"help": /* language=JavaScript */ `\
|
||||||
return new Command(
|
return new Command(
|
||||||
|
@ -519,8 +527,8 @@ return new Command(
|
||||||
|
|
||||||
const command = josh.interpreter.resolve(commandName);
|
const command = josh.interpreter.resolve(commandName);
|
||||||
if (command === undefined) {
|
if (command === undefined) {
|
||||||
streams.out.writeLine(\`Unknown command '\${commandName}'.\`);
|
streams.err.writeLine(\`help: Unknown command '\${commandName}'.\`);
|
||||||
return ExitCode.COMMAND_NOT_FOUND;
|
return ExitCode.USAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
let helpString = "<b>Name</b>\\n" + commandName;
|
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}
|
\`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(),
|
exist, it is created.\`.trimMultiLines(),
|
||||||
new InputValidator({minArgs: 1})
|
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 */ `\
|
"useradd": /* language=JavaScript */ `\
|
||||||
return new Command(
|
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}
|
\`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(),
|
that can be modified.\`.trimMultiLines(),
|
||||||
new InputValidator({minArgs: 1, maxArgs: 1})
|
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 */ `\
|
"whoami": /* language=JavaScript */ `\
|
||||||
return new Command(
|
return new Command(
|
||||||
|
|
|
@ -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", () => {
|
describe("help", () => {
|
||||||
beforeEach(() => loadCommand("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(execute("help help")).to.equal(ExitCode.OK);
|
||||||
expect(readOut()).to.not.equal("");
|
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", () => {
|
describe("useradd", () => {
|
||||||
before(() => HashProvider.default = plainHashProvider);
|
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", () => {
|
describe("whoami", () => {
|
||||||
beforeEach(() => loadCommand("whoami"));
|
beforeEach(() => loadCommand("whoami"));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue