Repository: yargs/yargs (js)

Issue:
commands: we should make builder, handler, description, command optional
It's not the case that we always wand a builder function for a command, I propose that we make each of these parameters optional.

Pull request description:
feat: providing a builder for commands is now optional
fixes #492 

Patch:
diff --git a/lib/command.js b/lib/command.js
index b753d3a..1dc8af9 100644
--- a/lib/command.js
+++ b/lib/command.js
@@ -11,14 +11,9 @@ module.exports = function (yargs, usage, validation) {
 
   var handlers = {}
   self.addHandler = function (cmd, description, builder, handler) {
-    // allow modules that define (a) all properties or (b) only command and description
     if (typeof cmd === 'object') {
       const commandString = typeof cmd.command === 'string' ? cmd.command : moduleName(cmd)
-      if (cmd.builder && typeof cmd.handler === 'function') {
-        self.addHandler(commandString, extractDesc(cmd), cmd.builder, cmd.handler)
-      } else {
-        self.addHandler(commandString, extractDesc(cmd))
-      }
+      self.addHandler(commandString, extractDesc(cmd), cmd.builder, cmd.handler)
       return
     }
 
@@ -39,6 +34,8 @@ module.exports = function (yargs, usage, validation) {
     handlers[parsedCommand.cmd] = {
       original: cmd,
       handler: handler,
+      // TODO: default to a noop builder in
+      // yargs@5.x
       builder: builder,
       demanded: parsedCommand.demanded,
       optional: parsedCommand.optional


Test patch:
diff --git a/test/command.js b/test/command.js
index 890fb8f..b28baf4 100644
--- a/test/command.js
+++ b/test/command.js
@@ -318,6 +318,26 @@ describe('Command', function () {
       var commands = y.getUsageInstance().getCommands()
       commands[0].should.deep.equal([module.command, module.describe])
     })
+
+    it('accepts module (missing handler function) as 1st argument', function () {
+      var module = {
+        command: 'foo',
+        describe: 'i\'m not feeling very creative at the moment',
+        builder: {
+          hello: {
+            default: 'world'
+          }
+        }
+      }
+
+      var y = yargs([]).command(module)
+      var handlers = y.getCommandInstance().getCommandHandlers()
+      handlers.foo.original.should.equal(module.command)
+      handlers.foo.builder.should.equal(module.builder)
+      expect(handlers.foo.handler).to.equal(undefined)
+      var commands = y.getUsageInstance().getCommands()
+      commands[0].should.deep.equal([module.command, module.describe])
+    })
   })
 
   describe('commandDir', function () {