Debian Codegraph @

tools/eos-application-manifest/commands/help.js

raw
1 // Copyright 2013 Endless Mobile, Inc.
2
3 const System = imports.system;
4
5 function execute(args) {
6 if (args.length === 0) {
7 print('Usage: %s <command> [<args>]\n'.format(System.programInvocationName));
8 // Query all available subcommands
9 let oldSearchPath = imports.searchPath;
10 imports.searchPath = [commandSearchPath]; // only pick up subcommands
11 let commandsList = [];
12 for (let commandName in imports) {
13 commandsList.push(commandName);
14 }
15 imports.searchPath = oldSearchPath;
16
17 // Print out summary for each subcommand
18 if (commandsList.length === 0)
19 return;
20 print('Summaries of commands:');
21 let maxWidth = commandsList.reduce(function (prev, curr) {
22 return Math.max(curr.length, prev);
23 }, 0);
24 commandsList.forEach(function (commandName) {
25 let command = imports[commandName];
26 let summary;
27 if (typeof command.summary == 'undefined')
28 summary = 'No information available';
29 else
30 summary = command.summary();
31 print(' %%%ds - %%s'.format(maxWidth).format(commandName, summary));
32 });
33 return;
34 }
35
36 const command = imports[args[0]];
37 command.help();
38 }
39
40 function summary() {
41 return 'Displays help information about a subcommand';
42 }
43
44 function help() {
45 print("Displays help information about a subcommand.\n\
46 Try '%s help <command-name>'.".format(System.programInvocationName));
47 }