summaryrefslogtreecommitdiff
path: root/Components/Documentation
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-11-28 17:31:34 +0100
committerMinteck <contact@minteck.org>2022-11-28 17:31:34 +0100
commit7923aa8942b55884320ef2428417e3ee4b121613 (patch)
tree7993632f2898b1998f25b11ce40a8d2eb3d44730 /Components/Documentation
downloadmistyos-og-mane.tar.gz
mistyos-og-mane.tar.bz2
mistyos-og-mane.zip
Initial commitHEADmane
Diffstat (limited to 'Components/Documentation')
-rw-r--r--Components/Documentation/index.js129
-rw-r--r--Components/Documentation/metadata.yml30
2 files changed, 159 insertions, 0 deletions
diff --git a/Components/Documentation/index.js b/Components/Documentation/index.js
new file mode 100644
index 0000000..1b0e132
--- /dev/null
+++ b/Components/Documentation/index.js
@@ -0,0 +1,129 @@
+const fs = require('fs');
+const path = require('path');
+const chalk = require(__dirname + '/../../MistyCore/node_modules/chalk');
+const child_process = require("child_process");
+const semver = require(__dirname + '/../../MistyCore/node_modules/semver');
+
+function prettyVersion(version) {
+ return version.replace(/^\*$/gm, "<all versions>").replace(/^>=(| *)(\d+\.\d+\.\d+)$/gm, "$2 and later").replace(/^=(| *)(\d+\.\d+\.\d+)$/gm, "$2").replace(/^(\d+\.\d+\.\d+)(| +)-(| +)(\d+\.\d+\.\d+)$/gm, "$1 to $4");
+}
+
+module.exports = (arguments) => {
+ if (arguments['_finals'].length === 0) {
+ console.log(chalk.bgYellow.white("<!>") + " " + chalk.yellow("Missing operand"));
+ return;
+ }
+
+ let input = arguments['_finals'][0];
+ let command = null;
+
+ let commands = global.commands;
+ let commandsMetadata = global.commandsMetadata;
+
+ for (let cmd of commands) {
+ if (cmd.toLowerCase() === input.toLowerCase()) {
+ command = cmd;
+ break;
+ }
+
+ let metadata = commandsMetadata[commands.indexOf(cmd)];
+ if (metadata['aliases'].map(i => i.toLowerCase()).includes(input.toLowerCase())) {
+ command = cmd;
+ break;
+ }
+ }
+
+ let metadata = commandsMetadata[commands.indexOf(command)];
+ if (!command) {
+ console.log(chalk.bgRed.white("<!>") + " " + chalk.red("Command not found: ") + input);
+ } else {
+ let out = chalk.reset("") + "\n";
+ let pack = "*";
+
+ out += chalk.red(" ╔" + "═".repeat(command.length + 2) + "╗\n ║ " + command + " ║\n " + "╚" + "═".repeat(command.length + 2) + "╝") + "\n\n";
+
+ out += chalk.magenta(" Name\n ----") + "\n";
+ out += chalk.whiteBright(" " + command + " - " + metadata.description) + "\n\n";
+
+ out += chalk.magenta(" Synopsis\n --------") + "\n";
+ out += chalk.whiteBright(" " + chalk.green(command));
+
+ for (let param of metadata['manual']['parameters']) {
+ out += " ";
+
+ if (!param.required) out += "[";
+ if (param.value) {
+ out += chalk.cyan("-" + param.name) + chalk.magenta(chalk.bgGray("=") + param.value);
+ } else {
+ out += chalk.magenta("-" + param.name);
+ }
+ if (!param.required) out += "]";
+ }
+
+ if (metadata['manual']['final']) {
+ out += " ";
+
+ if (!metadata['manual']['final'].required) out += "[";
+
+ if (metadata['manual']['final']['command']) {
+ out += chalk.yellow(metadata['manual']['final'].name);
+ } else {
+ out += metadata['manual']['final'].name;
+ }
+
+ if (metadata['manual']['final'].multiple) out += " ...";
+ if (!metadata['manual']['final'].required) out += "]";
+ }
+
+ out += "\n";
+
+ for (let alias of metadata.aliases) {
+ out += chalk.whiteBright(" " + chalk.green(alias) + chalk.gray(" (-> " + command + ")") + "\n");
+ }
+
+ if (metadata['manual']['summary'] || metadata['manual']['parameters'].length > 0) {
+ out += chalk.magenta("\n Description\n -----------") + "\n";
+ if (metadata['manual']['summary']) {
+ out += " " + metadata['manual']['summary'].trim();
+ for (let param of metadata['manual']['parameters']) {
+ out += "\n\n ";
+
+ if (param.value) {
+ out += chalk.cyan("-" + param.name) + chalk.magenta(chalk.bgGray("=") + param.value);
+ } else {
+ out += chalk.magenta("-" + param.name);
+ }
+
+ out += "\n " + param.description ?? "<no description>";
+ }
+
+ if (metadata['manual']['final']) {
+ out += "\n\n ";
+
+ if (metadata['manual']['final']['command']) {
+ out += chalk.yellow(metadata['manual']['final'].name);
+ } else {
+ out += metadata['manual']['final'].name;
+ }
+
+ if (metadata['manual']['final'].multiple) out += " ...";
+ out += "\n " + metadata['manual']['final'].description ?? "<no description>";
+ }
+ }
+ }
+
+ if (metadata['manual']['examples']) {
+ out += chalk.magenta("\n\n Examples\n --------") + "\n";
+
+ for (let example of metadata['manual']['examples']) {
+ out += " " + example.description + "\n " + chalk.blue("> ") + example.command + "\n";
+ }
+ }
+
+ out += chalk.magenta("\n\n Compatibility\n -------------") + "\n";
+ out += " MistyOS: " + prettyVersion(metadata['manual']['compatibility']['mistyos']) + "\n";
+ out += " Kernel: " + prettyVersion(metadata['manual']['compatibility']['kernel']);
+
+ console.log("\n" + out.trim() + "\n");
+ }
+} \ No newline at end of file
diff --git a/Components/Documentation/metadata.yml b/Components/Documentation/metadata.yml
new file mode 100644
index 0000000..799f509
--- /dev/null
+++ b/Components/Documentation/metadata.yml
@@ -0,0 +1,30 @@
+description: Shows documentation about a command
+internal: true
+
+aliases:
+ - man
+ - help
+ - docs
+
+manual:
+ summary: |
+ This command shows documentation about another command, including how to use it.
+
+ parameters: []
+
+ final:
+ name: Command
+ description: The command to get help for
+ required: true
+ multiple: false
+ command: true
+ path: false
+ daemon: false
+
+ examples:
+ - command: Documentation ChangeDir
+ description: Shows documentation for the ChangeDir command
+
+ compatibility:
+ mistyos: '>=1.0.0'
+ kernel: '>=5.10.0' \ No newline at end of file