"use strict";
var _ = require('../lodash.custom');
var common = '../opts/common.json';
var runcommon = '../opts/run-common.json';
var globalcommon = '../opts/global-common.json';
exports.commands = {
    run: {
        alias: ['run', 'r'],
        description: 'Run a task(s)',
        opts: [
            '../opts/command.run.opts.json',
            runcommon,
            globalcommon,
            common,
        ],
        help: "Usage: crossbow run [...tasks] [OPTIONS]\n\n{bold:Run Options:}\n\n" + optionsList(_.merge({}, require('../opts/command.run.opts.json'), require(runcommon))) + "\n\n{bold:Global Options:}\n\n" + optionsList(_.merge({}, require(globalcommon), require(common))) + "\n\n{bold:Example: run 2 named tasks in parallel} \n\n    $ crossbow run task1 task2 -p\n\n{bold:Example: use a config file from another folder} \n\n    $ crossbow run <task-name> -c .conf/crossbow.yaml\n    "
    },
    watch: {
        alias: ["watch", "w"],
        description: 'Run a watcher(s)',
        opts: [
            '../opts/command.watch.opts.json',
            runcommon,
            common
        ],
        help: "Usage: crossbow watch [...watcher] [OPTIONS]\n\n{bold:Watch Options:}\n\n" + twoColFromJson(_.merge({}, require('../opts/command.watch.opts.json'), require('../opts/run-common.json')), 'desc') + "\n\n{bold:Global Options:}\n\n" + twoColFromJson(_.merge({}, require(globalcommon), require(common)), 'desc') + "\n\n{bold:Example: run 2 named tasks in parallel} \n\n    $ crossbow run task1 task2 -p\n\n{bold:Example: use a config file from another folder} \n\n    $ crossbow run <task-name> -c .conf/crossbow.yaml\n    "
    },
    tasks: {
        alias: ["tasks", "t", "ls"],
        description: 'See your available top-level tasks',
        opts: [
            '../opts/command.tasks.opts.json',
            common,
            globalcommon
        ],
        help: "Usage: crossbow tasks [OPTIONS]\n\n{bold:Options:}\n\n" + twoColFromJson(_.merge({}, require(globalcommon), require(common)), 'desc') + "\n\n{bold:Example: show all available tasks} \n\n    $ crossbow tasks\n\n{bold:Example: show all tasks different config file} \n\n    $ crossbow tasks -c conf/config.js\n    "
    },
    watchers: {
        alias: ['watchers'],
        description: 'See your available watchers',
        opts: [
            '../opts/command.watchers.opts.json',
            globalcommon
        ],
        help: "Usage: crossbow watchers [OPTIONS]\n        \n{bold:Options:} \n\n" + twoColFromJson(_.merge({}, require(globalcommon)), 'desc') + "\n\n{bold:Example: Show watchers from a config file}\n\n    $ crossbow watchers -c conf/config.js\n"
    },
    init: {
        alias: ['init', 'i'],
        description: 'Create a configuration file',
        opts: [
            '../opts/command.init.opts.json',
            globalcommon
        ],
        help: "Usage: crossbow init [OPTIONS]\n\n{bold:Init Options:}\n\n" + twoColFromJson(_.merge({}, require('../opts/command.init.opts.json')), 'desc') + "\n\n{bold:Options:}\n\n" + twoColFromJson(_.merge({}, require(globalcommon)), 'desc') + "\n\n{bold:Examples: Create a config file in default format (yaml)}\n\n    $ crossbow init\n\n{bold:Examples: Create a config file in JSON format}\n\n    $ crossbow init --type json\n"
    },
    docs: {
        alias: ['docs'],
        description: 'Generate documentation automatically',
        opts: [
            '../opts/command.docs.opts.json',
            globalcommon
        ],
        help: "Usage: crossbow docs [OPTIONS]\n\n{bold:Docs Options:}\n\n" + twoColFromJson(_.merge({}, require('../opts/command.docs.opts.json')), 'desc') + "\n\n{bold:Options:}\n\n" + twoColFromJson(_.merge({}, require(globalcommon)), 'desc') + "\n\n{bold:Example: Generate documentation in the current directory}\n\n    $ crossbow docs\n\n{bold:Example: Create a NEW file containing documentation}\n\n    $ crossbow docs --output docs.md\n    \n{bold:Example: Override documentation in an existing file}\n\n    $ crossbow docs --file existing-docs.md\n"
    }
};
function optionsList(obj) {
    return twoColFromJson(obj, 'desc', function (key, subject) {
        var open = '--' + key;
        if (subject.alias && subject.alias.length) {
            return [open, ', '].concat(subject.alias.map(function (x) { return '-' + x; }).join(', ')).join('');
        }
        return open;
    });
}
function twoColFromJson(json, rightSidePropertyName, leftside) {
    if (!leftside)
        leftside = function (subject) { return subject; };
    var cols = Object.keys(json).map(function (key) {
        var subject = json[key];
        return [leftside(key, subject), json[key][rightSidePropertyName]];
    });
    var longest = cols.reduce(function (acc, item) {
        if (item[0].length > acc)
            return item[0].length;
        return acc;
    }, 0);
    var padded = cols.map(function (tuple) {
        if (tuple[0].length < longest) {
            return [tuple[0] + new Array(longest - tuple[0].length).join(' ') + ' ', tuple[1]];
        }
        return tuple;
    });
    return padded.reduce(function (acc, item) {
        return acc.concat('    ' + item.join('  '));
    }, []).join('\n');
}
exports.twoColFromJson = twoColFromJson;
//# sourceMappingURL=cli.commands.js.map