1
0
Fork 0
forked from svrjs/svrjs

refactor: move printing the command line usage to a separate function

This commit is contained in:
Dorian Niemiec 2024-09-02 18:07:07 +02:00
parent fe6853524e
commit 645223451a

View file

@ -113,6 +113,23 @@ process.messageEventListeners = [];
if (process.versions) process.versions.svrjs = version; // Inject SVR.JS into process.versions if (process.versions) process.versions.svrjs = version; // Inject SVR.JS into process.versions
// Function for printing the command line usage of SVR.JS
function printUsage() {
console.log(`${name} usage:`);
console.log(
"node svr.js [-h] [--help] [-?] [/h] [/?] [--secure] [--reset] [--clean] [--disable-mods] [--single-threaded] [-v] [--version]"
);
console.log("-h -? /h /? --help -- Displays help");
console.log("--clean -- Cleans up files created by " + name);
console.log(
`--reset -- Resets ${name} to default settings (WARNING: DANGEROUS)`
);
console.log("--secure -- Runs HTTPS server");
console.log("--disable-mods -- Disables mods (safe mode)");
console.log("--single-threaded -- Run single-threaded");
console.log("-v --version -- Display server version");
}
let exiting = false; let exiting = false;
let forceSecure = false; let forceSecure = false;
let disableMods = false; let disableMods = false;
@ -134,19 +151,7 @@ for (
args[i] == "/h" || args[i] == "/h" ||
args[i] == "/?" args[i] == "/?"
) { ) {
console.log(`${name} usage:`); printUsage();
console.log(
"node svr.js [-h] [--help] [-?] [/h] [/?] [--secure] [--reset] [--clean] [--disable-mods] [--single-threaded] [-v] [--version]"
);
console.log("-h -? /h /? --help -- Displays help");
console.log("--clean -- Cleans up files created by " + name);
console.log(
`--reset -- Resets ${name} to default settings (WARNING: DANGEROUS)`
);
console.log("--secure -- Runs HTTPS server");
console.log("--disable-mods -- Disables mods (safe mode)");
console.log("--single-threaded -- Run single-threaded");
console.log("-v --version -- Display server version");
process.exit(0); process.exit(0);
} else if (args[i] == "--secure") { } else if (args[i] == "--secure") {
forceSecure = true; forceSecure = true;
@ -179,19 +184,7 @@ for (
process.singleThreaded = true; process.singleThreaded = true;
} else { } else {
console.log(`Unrecognized argument: ${args[i]}`); console.log(`Unrecognized argument: ${args[i]}`);
console.log(`${name} usage:`); printUsage();
console.log(
"node svr.js [-h] [--help] [-?] [/h] [/?] [--secure] [--reset] [--clean] [--disable-mods] [--single-threaded] [-v] [--version]"
);
console.log("-h -? /h /? --help -- Displays help");
console.log("--clean -- Cleans up files created by " + name);
console.log(
`--reset -- Resets ${name} to default settings (WARNING: DANGEROUS)`
);
console.log("--secure -- Runs HTTPS server");
console.log("--disable-mods -- Disables mods (safe mode)");
console.log("--single-threaded -- Run single-threaded");
console.log("-v --version -- Display server version");
process.exit(1); process.exit(1);
} }
} }