#! /usr/bin/env node

'use strict';

(function () {

  var jargs = require('../src/index');
  var Program = jargs.Program;
  var Command = jargs.Command;
  var KWArg = jargs.KWArg;
  var Flag = jargs.Flag;
  var Arg = jargs.Arg;
  var Required = jargs.Required;
  var RequireAll = jargs.RequireAll;
  var RequireAny = jargs.RequireAny;

  var firstCommand = Command(
    'first',
    {
      description: 'The first command',
      usage: 'command first',
      examples: [
        'command first'
      ]
    }
  );

  var secondCommand = Command(
    'second',
    {
      description: 'The second command',
      usage: 'command second [--kwarg1, --kwarg2] arg',
      examples: [
        'command --kwarg1=foo --kwarg2=bar arg'
      ]
    },
    Flag(
      'flag',
      {
        alias: 'f',
        description: 'An optional flag'
      }
    ),
    RequireAll(
      KWArg(
        'kwarg1',
        {
          alias: '1',
          type: 'string',
          description: 'A required key word argument'
        }
      ),
      KWArg(
        'kwarg2',
        {
          alias: '2',
          type: 'string',
          description: 'Another required key word argument'
        }
      )
    ),
    Required(
      Arg(
        'arg'
      )
    )
  );

  var tree = jargs.collect(
    Program(
      'command',
      {
        description: 'An example command line interface',
        examples: [
          'command first arg',
          'command second --flag --kwarg1=foo --kwarg2=bar arg'
        ]
      },
      RequireAny(
        firstCommand,
        secondCommand
      )
    )
  );

  console.log(tree);

})();

@@ -498,22 +498,477 @@
 %0A      %5D
-%0A    %7D
+,%0A      callback: function (tree) %7B%0A        return tree.args.data;%0A      %7D%0A    %7D,%0A    RequireAll(%0A      Arg(%0A        'data',%0A        %7B%0A          description: 'Some data to be passed to the sub command'%0A        %7D%0A      ),%0A      Command(%0A        'sub',%0A        %7B%0A          description: 'A sub command',%0A          usage: 'command first sub',%0A          callback: function (tree, parentTree, data) %7B%0A            console.log(data);%0A          %7D%0A        %7D%0A      )%0A    )
 %0A  );%0A%0A 
@@ -2053,16 +2053,47 @@
 )%0A  );%0A%0A
+  console.log('Full tree:%5Cn');%0A
   consol

Update example1 to test returned data being pass to subsequent commands