fix displaying of help

v3
robinmoisson 2023-03-30 18:43:40 +02:00
rodzic 7e71c42037
commit ba206f1377
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 9419716500078583
1 zmienionych plików z 14 dodań i 9 usunięć

Wyświetl plik

@ -21,8 +21,20 @@ const yargs = parseCommandLineArguments();
const namedArgs = yargs.argv;
async function runStatiCrypt() {
const hasSaltFlag = isOptionSetByUser("s", yargs);
const hasShareFlag = isOptionSetByUser("share", yargs);
// validate the number of arguments
if (!hasShareFlag && !hasSaltFlag) {
const positionalArguments = namedArgs._;
if (positionalArguments.length === 0) {
yargs.showHelp();
process.exit(1);
}
}
// if the 's' flag is passed without parameter, generate a salt, display & exit
if (isOptionSetByUser("s", yargs) && !namedArgs.salt) {
if (hasSaltFlag && !namedArgs.salt) {
console.log(generateRandomSalt());
process.exit(0);
}
@ -35,7 +47,7 @@ async function runStatiCrypt() {
const password = await getValidatedPassword(namedArgs.password, namedArgs.short);
// display the share link with the hashed password if the --share flag is set
if (isOptionSetByUser("share", yargs)) {
if (hasShareFlag) {
const url = namedArgs.share || "";
const hashedPassword = await cryptoEngine.hashPassphrase(password, salt);
@ -44,13 +56,6 @@ async function runStatiCrypt() {
process.exit(0);
}
// validate the number of arguments
const positionalArguments = namedArgs._;
if (positionalArguments.length === 0) {
yargs.showHelp();
process.exit(1);
}
// write salt to config file
const isUsingconfigFile = namedArgs.config.toLowerCase() !== "false";
const configPath = "./" + namedArgs.config;