Skip to content

Commit 2f82e0c

Browse files
committed
refactor(bin): add function showUsage to refactor usage things
Signed-off-by: Erona <[email protected]>
1 parent 7b12945 commit 2f82e0c

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

bin/manage_users

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const models = require("../lib/models/");
88
const readline = require("readline-sync");
99
const minimist = require("minimist");
1010

11-
var usage = `
11+
function showUsage(tips) {
12+
console.log(`${tips}
1213
1314
Command-line utility to create users for email-signin.
1415
@@ -17,7 +18,9 @@ Usage: bin/manage_users [--pass password] (--add | --del) user-email
1718
--add Add user with the specified user-email
1819
--del Delete user with specified user-email
1920
--pass Use password from cmdline rather than prompting
20-
`
21+
`);
22+
process.exit(1);
23+
}
2124

2225
// Using an async function to be able to use await inside
2326
async function createUser(argv) {
@@ -74,16 +77,12 @@ var action = opts[0];
7477

7578
// Check for options missing
7679
if (opts.length === 0) {
77-
console.log(`You did not specify either ${keys.map((key) => `--${key}`).join(' or ')}!`);
78-
console.log(usage);
79-
process.exit(1);
80+
showUsage(`You did not specify either ${keys.map((key) => `--${key}`).join(' or ')}!`);
8081
}
8182

8283
// Check if both are specified
8384
if (opts.length > 1) {
84-
console.log(`You cannot ${action.join(' and ')} at the same time!`);
85-
console.log(usage);
86-
process.exit(1);
85+
showUsage(`You cannot ${action.join(' and ')} at the same time!`);
8786
}
8887

8988
// Call respective processing functions

0 commit comments

Comments
 (0)