diff options
author | Erona | 2018-10-29 22:11:43 +0800 |
---|---|---|
committer | Erona | 2018-10-29 23:11:19 +0800 |
commit | 2f82e0c86af60664372b1d9008fae0284c037557 (patch) | |
tree | f4895afedd97d869070702f4b656e50f2e6a4c7d /bin | |
parent | 7b12945c498464370f6f482c273a4ac535da74e8 (diff) |
refactor(bin): add function showUsage to refactor usage things
Signed-off-by: Erona <erona@loli.bz>
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/manage_users | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/bin/manage_users b/bin/manage_users index 8c615251..30b4632d 100755 --- a/bin/manage_users +++ b/bin/manage_users @@ -8,7 +8,8 @@ const models = require("../lib/models/"); const readline = require("readline-sync"); const minimist = require("minimist"); -var usage = ` +function showUsage(tips) { + console.log(`${tips} Command-line utility to create users for email-signin. @@ -17,7 +18,9 @@ Usage: bin/manage_users [--pass password] (--add | --del) user-email --add Add user with the specified user-email --del Delete user with specified user-email --pass Use password from cmdline rather than prompting -` +`); + process.exit(1); +} // Using an async function to be able to use await inside async function createUser(argv) { @@ -74,16 +77,12 @@ var action = opts[0]; // Check for options missing if (opts.length === 0) { - console.log(`You did not specify either ${keys.map((key) => `--${key}`).join(' or ')}!`); - console.log(usage); - process.exit(1); + showUsage(`You did not specify either ${keys.map((key) => `--${key}`).join(' or ')}!`); } // Check if both are specified if (opts.length > 1) { - console.log(`You cannot ${action.join(' and ')} at the same time!`); - console.log(usage); - process.exit(1); + showUsage(`You cannot ${action.join(' and ')} at the same time!`); } // Call respective processing functions |