List all environment variables given no-arg `set`

Fixes #134.
This commit is contained in:
Florine W. Dekker 2020-08-05 16:06:49 +02:00
parent b82eb4b9a1
commit 22c60dbbbd
Signed by: FWDekker
GPG Key ID: B1B567AF58D6EE0F
3 changed files with 19 additions and 11 deletions

BIN
package-lock.json generated

Binary file not shown.

View File

@ -1,6 +1,6 @@
{ {
"name": "fwdekker.com", "name": "fwdekker.com",
"version": "0.37.2", "version": "0.37.3",
"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",
@ -23,9 +23,9 @@
}, },
"devDependencies": { "devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.1", "@istanbuljs/nyc-config-typescript": "^1.0.1",
"@types/chai": "^4.2.11", "@types/chai": "^4.2.12",
"@types/js-cookie": "^2.2.6", "@types/js-cookie": "^2.2.6",
"@types/mocha": "^8.0.0", "@types/mocha": "^8.0.1",
"@types/semver": "^6.2.1", "@types/semver": "^6.2.1",
"chai": "^4.2.0", "chai": "^4.2.0",
"grunt": "^1.2.1", "grunt": "^1.2.1",
@ -33,15 +33,15 @@
"grunt-contrib-clean": "^2.0.0", "grunt-contrib-clean": "^2.0.0",
"grunt-contrib-copy": "^1.0.0", "grunt-contrib-copy": "^1.0.0",
"grunt-text-replace": "^0.4.0", "grunt-text-replace": "^0.4.0",
"grunt-webpack": "^3.1.3", "grunt-webpack": "^4.0.2",
"jsdom": "^16.3.0", "jsdom": "^16.3.0",
"jsdom-global": "^3.0.2", "jsdom-global": "^3.0.2",
"mocha": "^8.0.1", "mocha": "^8.1.1",
"nyc": "^15.1.0", "nyc": "^15.1.0",
"ts-loader": "^8.0.1", "ts-loader": "^8.0.1",
"ts-node": "^8.10.2", "ts-node": "^8.10.2",
"typescript": "^3.9.7", "typescript": "^3.9.7",
"webpack": "^4.43.0", "webpack": "^4.44.1",
"webpack-cli": "^3.3.12" "webpack-cli": "^3.3.12"
} }
} }

View File

@ -916,10 +916,15 @@ return new Command(
return new Command( return new Command(
(input, streams) => { (input, streams) => {
try { try {
if (input.argc === 1) if (input.argc === 0) {
Object.keys(josh.environment.variables)
.sort()
.forEach((key) => streams.out.writeLine(\`\${key} \${josh.environment.variables[key]}\`));
} else if (input.argc === 1) {
josh.environment.safeDelete(input.args[0]); josh.environment.safeDelete(input.args[0]);
else } else {
josh.environment.safeSet(input.args[0], input.args[1]); josh.environment.safeSet(input.args[0], input.args[1]);
}
return ExitCode.OK; return ExitCode.OK;
} catch (error) { } catch (error) {
@ -928,10 +933,13 @@ return new Command(
} }
}, },
\`set environment variable\`, \`set environment variable\`,
\`set <u>key</u> [<u>value</u>]\`, \`set [<u>key</u> [<u>value</u>]]\`,
\`Sets the environment variable <u>key</u> to <u>value</u>. If no <u>value</u> is given, the environment ${n} \`Sets the environment variable <u>key</u> to <u>value</u>. If no <u>value</u> is given, the environment ${n}
variable is cleared. Read-only variables cannot be set.\`.trimMultiLines(), variable is cleared. Read-only variables cannot be set or cleared.
new InputValidator({minArgs: 1, maxArgs: 2})
If neither <u>key</u> nor <u>value</u> is given, a list of all environment variables with current values is given.
\`.trimMultiLines(),
new InputValidator({minArgs: 0, maxArgs: 2})
)`, )`,
"touch": /* language=JavaScript */ `\ "touch": /* language=JavaScript */ `\
return new Command( return new Command(