mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Verify the number of arguments for ultimate commands
This commit is contained in:
parent
78e4a43916
commit
e01b06b238
2 changed files with 35 additions and 4 deletions
|
|
@ -20,7 +20,10 @@ import {
|
||||||
installUltimate,
|
installUltimate,
|
||||||
uninstallUltimate,
|
uninstallUltimate,
|
||||||
} from "../src/installation/installUltimate.js";
|
} from "../src/installation/installUltimate.js";
|
||||||
import {printUltimateLogs, troubleshootingExport } from "../src/ultimate/ultimateTroubleshooting.js";
|
import {
|
||||||
|
printUltimateLogs,
|
||||||
|
troubleshootingExport,
|
||||||
|
} from "../src/ultimate/ultimateTroubleshooting.js";
|
||||||
|
|
||||||
/** @type {string} */
|
/** @type {string} */
|
||||||
// This checks the current file's dirname in a way that's compatible with:
|
// This checks the current file's dirname in a way that's compatible with:
|
||||||
|
|
@ -68,20 +71,34 @@ if (tool) {
|
||||||
} else if (command === "setup") {
|
} else if (command === "setup") {
|
||||||
setup();
|
setup();
|
||||||
} else if (command === "ultimate") {
|
} else if (command === "ultimate") {
|
||||||
const subCommand = process.argv[3];
|
const cliArgs = initializeCliArguments(process.argv.slice(2));
|
||||||
|
const subCommand = cliArgs[1];
|
||||||
if (subCommand === "uninstall") {
|
if (subCommand === "uninstall") {
|
||||||
|
guardCliArgsMaxLenght(2, cliArgs, "safe-chain ultimate uninstall");
|
||||||
(async () => {
|
(async () => {
|
||||||
await uninstallUltimate();
|
await uninstallUltimate();
|
||||||
})();
|
})();
|
||||||
} else if (subCommand === "troubleshooting-logs") {
|
} else if (subCommand === "troubleshooting-logs") {
|
||||||
|
guardCliArgsMaxLenght(
|
||||||
|
2,
|
||||||
|
cliArgs,
|
||||||
|
"safe-chain ultimate troubleshooting-logs",
|
||||||
|
);
|
||||||
(async () => {
|
(async () => {
|
||||||
await printUltimateLogs();
|
await printUltimateLogs();
|
||||||
})();
|
})();
|
||||||
} else if (subCommand === "troubleshooting-export") {
|
} else if (subCommand === "troubleshooting-export") {
|
||||||
|
guardCliArgsMaxLenght(
|
||||||
|
2,
|
||||||
|
cliArgs,
|
||||||
|
"safe-chain ultimate troubleshooting-export",
|
||||||
|
);
|
||||||
(async () => {
|
(async () => {
|
||||||
await troubleshootingExport();
|
await troubleshootingExport();
|
||||||
})();
|
})();
|
||||||
} else {
|
} else {
|
||||||
|
guardCliArgsMaxLenght(1, cliArgs, "safe-chain ultimate");
|
||||||
|
// Install command = when no subcommand is provided (safe-chain ultimate)
|
||||||
(async () => {
|
(async () => {
|
||||||
await installUltimate();
|
await installUltimate();
|
||||||
})();
|
})();
|
||||||
|
|
@ -104,6 +121,22 @@ if (tool) {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Number} maxLength
|
||||||
|
* @param {String[]} args
|
||||||
|
* @param {String} command
|
||||||
|
*/
|
||||||
|
function guardCliArgsMaxLenght(maxLength, args, command) {
|
||||||
|
if (args.length > maxLength) {
|
||||||
|
ui.writeError(`Unexpected number of arguments for command ${command}.`);
|
||||||
|
ui.emptyLine();
|
||||||
|
|
||||||
|
writeHelp();
|
||||||
|
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function writeHelp() {
|
function writeHelp() {
|
||||||
ui.writeInformation(
|
ui.writeInformation(
|
||||||
chalk.bold("Usage: ") + chalk.cyan("safe-chain <command>"),
|
chalk.bold("Usage: ") + chalk.cyan("safe-chain <command>"),
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,6 @@ export async function uninstallUltimate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function installUltimate() {
|
export async function installUltimate() {
|
||||||
initializeCliArguments(process.argv);
|
|
||||||
|
|
||||||
const operatingSystem = platform();
|
const operatingSystem = platform();
|
||||||
|
|
||||||
if (operatingSystem === "win32") {
|
if (operatingSystem === "win32") {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue