'use strict';

var exists = require('fs-exists-sync');

/**
 * Run the given generators and tasks. This flag is unnecessary when
 * used with [base-runner][].
 *
 * ```sh
 * # run task 'foo'
 * $ app --tasks foo
 * # => {task: ['foo']}
 * # run generator 'foo', task 'bar'
 * $ app --tasks foo:bar
 * # => {task: ['foo:bar']}
 * ```
 * @name tasks
 * @api public
 * @cli public
 */

module.exports = function(app, options) {
  return function(val, key, config, next) {
    var tasks = setTasks(app, options.env.configFile, val);
    app.generate(tasks, next);
  };
};

/**
 * Determine the task to run
 */

function setTasks(app, configFile, tasks) {
  tasks = tasks.map(function(task) {
    if (task.indexOf('help') === 0) {
      return 'defaults:' + task;
    }
    return task;
  });

  if (tasks.length === 1) {
    var task = tasks[0];
    switch (task) {
      case 'default':
        // if a `generator.js` does not exist in user's cwd, run the "help" task
        if (!exists(configFile)) {
          return ['defaults:help'];
        }
        return ['default:default'];
      case 'render':
        return ['defaults:render'];
      default:
        return tasks;
    }
  }
  return tasks;
}

@@ -47,16 +47,75 @@
 -sync');
+%0Avar argv = require('yargs-parser')(process.argv.slice(2));
 %0A%0A/**%0A *
@@ -529,20 +529,21 @@
     
-var tasks = 
+app.generate(
 setT
@@ -547,21 +547,16 @@
 etTasks(
-app, 
 options.
@@ -575,36 +575,15 @@
 le, 
-val);%0A    app.generate(tasks
+argv._)
 , ne
@@ -652,21 +652,16 @@
 etTasks(
-app, 
 configFi
@@ -673,16 +673,39 @@
 asks) %7B%0A
+  tasks = tasks %7C%7C %5B%5D;%0A
   tasks 

simplify task processing