/**
 * Run "{{command.name}}".
 * @memberof module:{{pkg.nam}}/lib
 * @function {{command.name}}
{{#each command.params}} * @param {string} {{@key}} - {{this}}.
{{/each}} * @param {object} [options] - Optional settings.
{{#each command.options}} * @param {{#if type}}{string}{{else}}{boolean}{{/if}} [options.{{@key}}{{#if default}}={{{default}}}{{/if}}] - {{desc}}.
{{/each}}
 * @param {function} [callback] - Callback when done.
 */

"use strict";

var argx = require('argx'),
    async = require('async'),
{{#if command.options.configuration}}    apemanfile = require('apemanfile'),
{{/if}}    {{pascalcase command.name}}Runner = require('./{{command.name}}_runner');

/** @lends {{command.name}} */
function {{command.name}}({{#each command.params}}{{@key}}, {{/each}}options, callback) {
    var args = argx(arguments);
{{#each command.params}}    {{@key}} = args.shift();
{{/each}}    callback = args.pop('function') || argx.noop;
    options = args.pop('object') || {};

    async.waterfall([
{{#if command.options.configuration}}        function (callback) {
            apemanfile.load(options.configuration, callback);
        },
{{/if}}        function (apemanfile, callback) {
            var runner = new {{pascalcase command.name}}Runner({
{{#each command.options}}                {{@key}}: options.{{@key}}{{#if default}} || {{{default}}}{{/if}},
{{/each}}                apemanfile: apemanfile
            });
            runner.run({{#each command.params}}{{@key}}, {{/each}}callback);
        }
    ], callback);

}

module.exports = {{command.name}};