From 2c7bbef8b26590f040ee4f855cc3885a1287748c Mon Sep 17 00:00:00 2001 From: Darek Kay Date: Thu, 31 Oct 2019 10:33:47 +0100 Subject: [PATCH] Show an error and help if a CLI command is missing See also: https://github.com/tj/commander.js/issues/432 --- bin/static-marks.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bin/static-marks.js b/bin/static-marks.js index 0971f52..4199390 100644 --- a/bin/static-marks.js +++ b/bin/static-marks.js @@ -10,7 +10,7 @@ const importBookmarks = require("./import"); program .description(pkg.description) - .usage("[options] ") + .usage(" [options]") .version(pkg.version); // build @@ -44,6 +44,11 @@ program program.parse(process.argv); -if (program.args.length === 0) { +// eslint-disable-next-line no-underscore-dangle +const commands = program.args.filter(argument => argument._name); + +// missing/unknown subcommand +if (program.args.length === 0 || commands.length === 0) { + console.error(`Error: Missing or unknown command.\n`); program.help(); }