mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 11:16:31 -05:00
refactor(bin): add function showUsage to refactor usage things
Signed-off-by: Erona <erona@loli.bz>
This commit is contained in:
parent
7b12945c49
commit
2f82e0c86a
1 changed files with 7 additions and 8 deletions
|
@ -8,7 +8,8 @@ const models = require("../lib/models/");
|
||||||
const readline = require("readline-sync");
|
const readline = require("readline-sync");
|
||||||
const minimist = require("minimist");
|
const minimist = require("minimist");
|
||||||
|
|
||||||
var usage = `
|
function showUsage(tips) {
|
||||||
|
console.log(`${tips}
|
||||||
|
|
||||||
Command-line utility to create users for email-signin.
|
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
|
--add Add user with the specified user-email
|
||||||
--del Delete user with specified user-email
|
--del Delete user with specified user-email
|
||||||
--pass Use password from cmdline rather than prompting
|
--pass Use password from cmdline rather than prompting
|
||||||
`
|
`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
// Using an async function to be able to use await inside
|
// Using an async function to be able to use await inside
|
||||||
async function createUser(argv) {
|
async function createUser(argv) {
|
||||||
|
@ -74,16 +77,12 @@ var action = opts[0];
|
||||||
|
|
||||||
// Check for options missing
|
// Check for options missing
|
||||||
if (opts.length === 0) {
|
if (opts.length === 0) {
|
||||||
console.log(`You did not specify either ${keys.map((key) => `--${key}`).join(' or ')}!`);
|
showUsage(`You did not specify either ${keys.map((key) => `--${key}`).join(' or ')}!`);
|
||||||
console.log(usage);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if both are specified
|
// Check if both are specified
|
||||||
if (opts.length > 1) {
|
if (opts.length > 1) {
|
||||||
console.log(`You cannot ${action.join(' and ')} at the same time!`);
|
showUsage(`You cannot ${action.join(' and ')} at the same time!`);
|
||||||
console.log(usage);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call respective processing functions
|
// Call respective processing functions
|
||||||
|
|
Loading…
Reference in a new issue