mirror of
https://github.com/caprover/caprover
synced 2026-09-25 08:05:35 +00:00
Refactor messageHandler and catch unknown commands
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const { printErrorAndExit } = require("./utils/messageHandler")
|
||||
const packagejson = require("./package.json")
|
||||
const updateNotifier = require("update-notifier")
|
||||
const program = require("commander")
|
||||
@@ -48,4 +49,13 @@ program
|
||||
list()
|
||||
})
|
||||
|
||||
// Error on unknown commands
|
||||
program.on("command:*", () => {
|
||||
const wrongCommands = program.args.join(" ")
|
||||
|
||||
printErrorAndExit(
|
||||
`\nInvalid command: ${wrongCommands}\nSee --help for a list of available commands.\n`
|
||||
)
|
||||
})
|
||||
|
||||
program.parse(process.argv)
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
const chalk = require("chalk")
|
||||
|
||||
function printErrorAndExit(error) {
|
||||
console.log(`${chalk.bold.red(error)}\n\n`)
|
||||
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
module.exports = printErrorAndExit
|
||||
@@ -0,0 +1,26 @@
|
||||
const chalk = require("chalk")
|
||||
|
||||
function printMessage(message) {
|
||||
console.log(message)
|
||||
}
|
||||
|
||||
function printGreenMessage(message) {
|
||||
console.log(`${chalk.green(message)}`)
|
||||
}
|
||||
|
||||
function printError(error) {
|
||||
console.log(`${chalk.bold.red(error)}`)
|
||||
}
|
||||
|
||||
function printErrorAndExit(error) {
|
||||
console.log(`${printError(error)}`)
|
||||
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
printMessage,
|
||||
printErrorAndExit,
|
||||
printError,
|
||||
printGreenMessage
|
||||
}
|
||||
Reference in New Issue
Block a user