'a'
mh-two-thousand-and-two
2024-04-12 44d2c92345cd156a59fc327b3060292a282d2893
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var template = require('./template');
var each = require('./each');
var map = require('./map');
var rpad = require('./rpad');
var ansiColor = require('./ansiColor');
var toArr = require('./toArr');
var cloneDeep = require('./cloneDeep');
var strWidth = require('./strWidth');
var max = require('./max');
exports = function(data) {
    data = cloneDeep(data);
    data.usage = toArr(data.usage);
    if (data.commands) {
        var cmdNameWidths = map(data.commands, function(command) {
            return strWidth(command.name);
        });
        data.maxNameWidth = max.apply(null, cmdNameWidths);
        return helpTpl(data);
    }
    each(data.options, function(option) {
        option.name =
            (option.shorthand ? '-' + option.shorthand + ', ' : '    ') +
            '--' +
            option.name;
    });
    var optNameWidths = map(data.options, function(option) {
        return strWidth(option.name);
    });
    data.maxNameWidth = max.apply(null, optNameWidths);
    return cmdTpl(data);
};
var tplUtil = {
    each: each
};
tplUtil.rpad = function(text, len) {
    return rpad(text, len, ' ');
};
each(['yellow', 'green', 'cyan', 'red', 'white', 'magenta'], function(color) {
    tplUtil[color] = function(text) {
        return ansiColor[color](text);
    };
});
var cmdTpl = template(
    [
        'Usage:',
        '',
        "<% util.each(usage, function (value) { %>  <%=util.cyan(name)%> <%=value%><%='\\n'%><% }); %>",
        '<% if (options) { %>Options:',
        '',
        "<%     util.each(options, function (option) { %>  <%=util.yellow(util.rpad(option.name, maxNameWidth))%> <%=option.desc%><%='\\n'%><% }); %>",
        '<% } %>Description:',
        '',
        '  <%=desc%>'
    ].join('\n'),
    tplUtil
);
var helpTpl = template(
    [
        'Usage:',
        '',
        "<% util.each(usage, function (value) { %>  <%=util.cyan(name)%> <%=value%><%='\\n'%><% }); %>",
        'Commands:',
        '',
        "<% util.each(commands, function (command) { %>  <%=util.yellow(util.rpad(command.name, maxNameWidth))%> <%=command.desc%><%='\\n'%><% }); %>",
        "Run '<%=util.cyan(name + ' help <command>')%>' for more information on a specific command"
    ].join('\n'),
    tplUtil
);
 
module.exports = exports;