mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-24 02:03:01 +02:00
CODEBASE: Expand lint rules, and Aliases are stored as maps (#501)
This commit is contained in:
@@ -4,15 +4,13 @@ import { ScriptArg } from "../Netscript/ScriptArg";
|
||||
import { NetscriptContext } from "../Netscript/APIWrapper";
|
||||
|
||||
type FlagType = StringConstructor | NumberConstructor | BooleanConstructor | StringConstructor[];
|
||||
type FlagsRet = { [key: string]: ScriptArg | string[] };
|
||||
type FlagsRet = Record<string, ScriptArg | string[]>;
|
||||
export function Flags(ctx: NetscriptContext | string[]): (data: unknown) => FlagsRet {
|
||||
const vargs = Array.isArray(ctx) ? ctx : ctx.workerScript.args;
|
||||
return (schema: unknown): FlagsRet => {
|
||||
schema = toNative(schema);
|
||||
if (!Array.isArray(schema)) throw new Error("flags schema passed in is invalid.");
|
||||
const args: {
|
||||
[key: string]: FlagType;
|
||||
} = {};
|
||||
const args: Record<string, FlagType> = {};
|
||||
|
||||
for (const d of schema) {
|
||||
let t: FlagType = String;
|
||||
@@ -28,7 +26,7 @@ export function Flags(ctx: NetscriptContext | string[]): (data: unknown) => Flag
|
||||
}
|
||||
const ret: FlagsRet = libarg(args, { argv: vargs });
|
||||
for (const d of schema) {
|
||||
if (!ret.hasOwnProperty("--" + d[0]) || !ret.hasOwnProperty("-" + d[0])) ret[d[0]] = d[1];
|
||||
if (!Object.hasOwn(ret, "--" + d[0]) || !Object.hasOwn(ret, "-" + d[0])) ret[d[0]] = d[1];
|
||||
}
|
||||
for (const key of Object.keys(ret)) {
|
||||
if (!key.startsWith("-")) continue;
|
||||
|
||||
Reference in New Issue
Block a user