mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-26 17:43:48 +01:00
Merge pull request #2009 from hexnaught/script-exists-command-errors-patch
Better feedback when looking for a running script.
This commit is contained in:
commit
f5f206561c
@ -1,3 +1,5 @@
|
|||||||
|
export const validScriptExtensions: Array<string> = [`.js`, `.script`, `.ns`];
|
||||||
|
|
||||||
export function isScriptFilename(f: string): boolean {
|
export function isScriptFilename(f: string): boolean {
|
||||||
return f.endsWith(".js") || f.endsWith(".script") || f.endsWith(".ns");
|
return validScriptExtensions.some((ext) => f.endsWith(ext));
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ import { IRouter } from "../../ui/Router";
|
|||||||
import { IPlayer } from "../../PersonObjects/IPlayer";
|
import { IPlayer } from "../../PersonObjects/IPlayer";
|
||||||
import { BaseServer } from "../../Server/BaseServer";
|
import { BaseServer } from "../../Server/BaseServer";
|
||||||
import { findRunningScript } from "../../Script/ScriptHelpers";
|
import { findRunningScript } from "../../Script/ScriptHelpers";
|
||||||
import { isScriptFilename } from "../../Script/isScriptFilename";
|
import { isScriptFilename, validScriptExtensions } from "../../Script/isScriptFilename";
|
||||||
|
|
||||||
export function check(
|
export function check(
|
||||||
terminal: ITerminal,
|
terminal: ITerminal,
|
||||||
@ -13,19 +13,21 @@ export function check(
|
|||||||
args: (string | number | boolean)[],
|
args: (string | number | boolean)[],
|
||||||
): void {
|
): void {
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
terminal.error("Incorrect number of arguments. Usage: check [script] [arg1] [arg2]...");
|
terminal.error(`Incorrect number of arguments. Usage: check [script] [arg1] [arg2]...`);
|
||||||
} else {
|
} else {
|
||||||
const scriptName = terminal.getFilepath(args[0] + "");
|
const scriptName = terminal.getFilepath(args[0] + "");
|
||||||
// Can only tail script files
|
// Can only tail script files
|
||||||
if (!isScriptFilename(scriptName)) {
|
if (!isScriptFilename(scriptName)) {
|
||||||
terminal.error("tail can only be called on .script files (filename must end with .script)");
|
terminal.error(
|
||||||
|
`'check' can only be called on scripts files (filename must end with ${validScriptExtensions.join(", ")})`,
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the script exists on this machine
|
// Check that the script is running on this machine
|
||||||
const runningScript = findRunningScript(scriptName, args.slice(1), server);
|
const runningScript = findRunningScript(scriptName, args.slice(1), server);
|
||||||
if (runningScript == null) {
|
if (runningScript == null) {
|
||||||
terminal.error("No such script exists");
|
terminal.error(`No script named ${scriptName} is running on the server`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
runningScript.displayLog();
|
runningScript.displayLog();
|
||||||
|
@ -27,7 +27,7 @@ export function kill(
|
|||||||
if (res) {
|
if (res) {
|
||||||
terminal.print(`Killing script with PID ${pid}`);
|
terminal.print(`Killing script with PID ${pid}`);
|
||||||
} else {
|
} else {
|
||||||
terminal.error(`Failed to kill script with PID ${pid}. No such script exists`);
|
terminal.error(`Failed to kill script with PID ${pid}. No such script is running`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -29,7 +29,7 @@ export function mem(
|
|||||||
|
|
||||||
const script = terminal.getScript(player, scriptName);
|
const script = terminal.getScript(player, scriptName);
|
||||||
if (script == null) {
|
if (script == null) {
|
||||||
terminal.error("No such script exists!");
|
terminal.error("mem failed. No such script exists!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ export function scp(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sourceScript == null) {
|
if (sourceScript == null) {
|
||||||
terminal.error("scp() failed. No such script exists");
|
terminal.error("scp failed. No such script exists");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import { IRouter } from "../../ui/Router";
|
|||||||
import { IPlayer } from "../../PersonObjects/IPlayer";
|
import { IPlayer } from "../../PersonObjects/IPlayer";
|
||||||
import { BaseServer } from "../../Server/BaseServer";
|
import { BaseServer } from "../../Server/BaseServer";
|
||||||
import { findRunningScriptByPid } from "../../Script/ScriptHelpers";
|
import { findRunningScriptByPid } from "../../Script/ScriptHelpers";
|
||||||
import { isScriptFilename } from "../../Script/isScriptFilename";
|
import { isScriptFilename, validScriptExtensions } from "../../Script/isScriptFilename";
|
||||||
import { compareArrays } from "../../utils/helpers/compareArrays";
|
import { compareArrays } from "../../utils/helpers/compareArrays";
|
||||||
import { LogBoxEvents } from "../../ui/React/LogBoxManager";
|
import { LogBoxEvents } from "../../ui/React/LogBoxManager";
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ export function tail(
|
|||||||
} else if (typeof commandArray[0] === "string") {
|
} else if (typeof commandArray[0] === "string") {
|
||||||
const scriptName = terminal.getFilepath(commandArray[0]);
|
const scriptName = terminal.getFilepath(commandArray[0]);
|
||||||
if (!isScriptFilename(scriptName)) {
|
if (!isScriptFilename(scriptName)) {
|
||||||
terminal.error("tail can only be called on .script, .ns, .js files, or by pid");
|
terminal.error(`tail can only be called on ${validScriptExtensions.join(", ")} files, or by PID`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,11 +66,11 @@ export function tail(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if there's no candidate then we just don't know.
|
// if there's no candidate then we just don't know.
|
||||||
terminal.error("No such script exists.");
|
terminal.error(`No script named ${scriptName} is running on the server`);
|
||||||
} else if (typeof commandArray[0] === "number") {
|
} else if (typeof commandArray[0] === "number") {
|
||||||
const runningScript = findRunningScriptByPid(commandArray[0], server);
|
const runningScript = findRunningScriptByPid(commandArray[0], server);
|
||||||
if (runningScript == null) {
|
if (runningScript == null) {
|
||||||
terminal.error("No such script exists");
|
terminal.error(`No script with PID ${commandArray[0]} is running on the server`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LogBoxEvents.emit(runningScript);
|
LogBoxEvents.emit(runningScript);
|
||||||
|
Loading…
Reference in New Issue
Block a user