From 355a9fe590dbd9dbc8fd61059f335cd38bddb7da Mon Sep 17 00:00:00 2001 From: Zak Timson Date: Thu, 10 Feb 2022 17:43:41 +0000 Subject: [PATCH] More documentation --- README.md | 2 ++ scripts/lib/arg-parser.js | 13 +++++++++++++ scripts/node-manager.js | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 59f4e77..e456a6b 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,8 @@ It's recommended you run this in combination with `auto-pwn.js` to gain root & r ### [node-manager.js](./scripts/node-manager.js) **RAM:** 5.70 GB + +Buy, upgrade & manage Hacknet nodes automatically. ``` [home ~/]> run scripts/node-manager.js --help Running script with 1 thread(s), pid 128 and args: ["--help"]. diff --git a/scripts/lib/arg-parser.js b/scripts/lib/arg-parser.js index 179c7c0..a0253d1 100644 --- a/scripts/lib/arg-parser.js +++ b/scripts/lib/arg-parser.js @@ -1,10 +1,19 @@ export class ArgParser { + /** + * Create a unix-like argument parser to extract flags from the argument list. Can also create help messages. + * @param opts - {examples: string[], arguments: {key: string, alias: string, type: string, optional: boolean, desc: string}[], desc: string} + */ constructor(opts) { this.examples = opts.examples ?? []; this.arguments = opts.args ?? []; this.description = opts.desc; } + /** + * Parse the list for arguments & create a dictionary. + * @param args {any[]} - Array of arguments + * @returns Dictionary of matched flags + unmatched args under 'extra' + */ parse(args) { const req = this.arguments.filter(a => !a.optional); const queue = [...args]; @@ -29,6 +38,10 @@ export class ArgParser { return parsed; } + /** + * Create a help message of the expected paramters & usage. + * @param msg {String} - Optional message to display with help + */ help(msg) { let message = '\n\n'; message += msg ? msg : this.description; diff --git a/scripts/node-manager.js b/scripts/node-manager.js index 128c8b3..d8953e8 100644 --- a/scripts/node-manager.js +++ b/scripts/node-manager.js @@ -9,7 +9,7 @@ export async function main(ns) { /** * Print header with logs - * message - message to append to logs + * @param message - message to append to logs */ function log(message) { ns.clearLog();