forked from alainbryden/bitburner-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-command.js
21 lines (20 loc) · 1.24 KB
/
run-command.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { runCommand } from './helpers.js'
/** @param {NS} ns
* The argument can consist of multiple commands to run. The output of the first command will automatically be printed
* unless a subsequent command includes '; output = ...' - in which case that result will be printed instead. **/
export async function main(ns) {
let args = ns.args;
if (args.length == 0)
return ns.tprint("You must run this script with an argument that is the code to test.")
// Special first argument of -s will result in "silent" mode - do not output the result in the success case
let silent = false;
if (args.includes('-s')) {
silent = true;
args = args.slice(args.indexOf('-s'), 1);
}
let firstArg = String(args[0]);
let escaped = firstArg.startsWith('"') && firstArg.endsWith('"') || firstArg.startsWith("'") && firstArg.endsWith("'") || firstArg.startsWith("`") && firstArg.endsWith("`");
let command = args == escaped ? args[0] : args.join(" "); // If args weren't escaped, join them together
//3.6 return await runCommand(ns.run, ns.write, command, `/Temp/terminal-command.js`, !silent);
return await runCommand(ns, command, `/Temp/terminal-command.js`, !silent, 1, undefined, undefined, ...args.slice(1));
}