Make run() print help if no matches

This commit is contained in:
Juan Cruz Viotti 2014-11-20 12:05:50 -04:00
parent 14459e1d09
commit 91567cb5c7
3 changed files with 9 additions and 0 deletions

View File

@ -5,6 +5,8 @@ config = require('./config')
yargs = require('yargs')
yargs.command = require('./yargs-command/yargs-command')
yargs.usage('$0 [options] <command>')
# ---------- Auth Module ----------
auth = require('./actions/auth')

View File

@ -26,6 +26,8 @@ commandApplies = (command, args) ->
return true
run = ->
if not @command._matchedCommand?
return console.log(@help())
signature = splitSignature(@command._matchedCommand.signature)
parameters = _.difference(@argv._, signature)
@command._matchedCommand.action.apply(this, parameters)

View File

@ -108,3 +108,8 @@ describe 'Yargs Command:', ->
yargs.command(COMMANDS.appList.signature, callback)
yargs.command.run()
expect(callback).to.have.been.calledWith(_.last(ARGS.appList._))
it 'should print help if no matches', ->
helpSpy = sinon.spy(yargs, 'help')
yargs.command.run()
expect(helpSpy).to.have.been.called