summaryrefslogtreecommitdiff
path: root/tools/eos-application-manifest/commands/help.js
blob: d26b95c97a4dd3503829c6d531d3fc9fc8a926a8 (plain)
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
// Copyright 2013 Endless Mobile, Inc.

const System = imports.system;

function execute(args) {
    if (args.length === 0) {
        print('Usage: %s <command> [<args>]\n'.format(System.programInvocationName));
        // Query all available subcommands
        let oldSearchPath = imports.searchPath;
        imports.searchPath = [commandSearchPath]; // only pick up subcommands
        let commandsList = [];
        for (let commandName in imports) {
            commandsList.push(commandName);
        }
        imports.searchPath = oldSearchPath;

        // Print out summary for each subcommand
        if (commandsList.length === 0)
            return;
        print('Summaries of commands:');
        let maxWidth = commandsList.reduce(function (prev, curr) {
            return Math.max(curr.length, prev);
        }, 0);
        commandsList.forEach(function (commandName) {
            let command = imports[commandName];
            let summary;
            if (typeof command.summary == 'undefined')
                summary = 'No information available';
            else
                summary = command.summary();
            print('  %%%ds - %%s'.format(maxWidth).format(commandName, summary));
        });
        return;
    }

    const command = imports[args[0]];
    command.help();
}

function summary() {
    return 'Displays help information about a subcommand';
}

function help() {
    print("Displays help information about a subcommand.\n\
Try '%s help <command-name>'.".format(System.programInvocationName));
}