From 938d9f07b79365cd07b13ff6f3d32621b51a1064 Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Tue, 8 Mar 2016 09:58:32 -0800 Subject: [PATCH] When user runs unknown command, show the help Closes #178 Also something to investigate would be to do a fuzzy search for what the user intended to type and suggest that: https://github.com/tj/commander.js/issues/432#issuecomment-175815584 --- bin/index.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bin/index.js b/bin/index.js index 97b9334a7310c..cfa4b5f60eb8e 100644 --- a/bin/index.js +++ b/bin/index.js @@ -1,6 +1,9 @@ /*eslint-disable */ var program = require('commander') var packageJson = require('../package.json') +var _ = require('lodash') +var subCmd +var cmds /*eslint-enable */ program @@ -9,3 +12,11 @@ program .command('build [directory]', 'Do a production build of site') .command('new [rootPath] [starter]', 'Create new Gatsby project in path [.].') .parse(process.argv) + +// If the user types an unknown sub-command, just display the help. +subCmd = _.head(program.args) +cmds = _.map(program.commands, '_name') + +if (!_.includes(cmds, subCmd)) { + program.help() +}