From a3f0b86fea4f8aafbd561c1a8e102cc4cd290828 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 25 May 2020 18:21:37 +0200 Subject: [PATCH] Can show command line help --- src/help.ts | 16 ++++++++++++++++ src/main.ts | 15 ++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/help.ts diff --git a/src/help.ts b/src/help.ts new file mode 100644 index 0000000..e84fcce --- /dev/null +++ b/src/help.ts @@ -0,0 +1,16 @@ +/** + * Command-line usage help + * + * @author Pierre Hubert + */ + +export function showHelp() { + console.info( + "Usage:\n" + + "* server (default) : Start the API server\n" + + "* help : Show this message\n" + + "* migration [mig_id] : Start a migration" + ); + + process.exit(0); +} \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 850e632..f692c04 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,7 @@ import { ConfigurationHelper } from "./helpers/ConfigHelper"; import { DatabaseHelper } from "./helpers/DatabaseHelper"; import { startServer } from "./server"; +import { showHelp } from "./help"; /** * Main project script @@ -20,6 +21,18 @@ async function init() { console.info("Connect to database"); await DatabaseHelper.connect(); - await startServer(); + const action = process.argv.length < 4 ? "server" : process.argv[3]; + + switch(action) { + case "help": + showHelp(); + break; + + case "server": + await startServer(); + break; + + + } } init(); \ No newline at end of file