summaryrefslogtreecommitdiff
path: root/tools/eos-application-manifest/commands
diff options
context:
space:
mode:
authorPhilip Chimento <philip@endlessm.com>2013-07-08 16:36:54 -0700
committerPhilip Chimento <philip@endlessm.com>2013-10-18 14:02:26 -0700
commit9d0850b4fb74d21f7e3a5189567ef80fc0239b75 (patch)
treeb0fb93c7861eb8e471d1ddc49b064c6288d96dd1 /tools/eos-application-manifest/commands
parent60369d32ec26deba64766b58b4470d7b9c8a629f (diff)
'eos-application-manifest' tool with subcommands
This is the framework for an 'eos-application-manifest' tool with subcommands as in git. Currently the 'help' and 'version' subcommands are implemented. [endlessm/eos-sdk#152]
Diffstat (limited to 'tools/eos-application-manifest/commands')
-rw-r--r--tools/eos-application-manifest/commands/help.js47
-rw-r--r--tools/eos-application-manifest/commands/version.js15
2 files changed, 62 insertions, 0 deletions
diff --git a/tools/eos-application-manifest/commands/help.js b/tools/eos-application-manifest/commands/help.js
new file mode 100644
index 0000000..d991b85
--- /dev/null
+++ b/tools/eos-application-manifest/commands/help.js
@@ -0,0 +1,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.length);
+ });
+ 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));
+}
diff --git a/tools/eos-application-manifest/commands/version.js b/tools/eos-application-manifest/commands/version.js
new file mode 100644
index 0000000..160b82a
--- /dev/null
+++ b/tools/eos-application-manifest/commands/version.js
@@ -0,0 +1,15 @@
+// Copyright 2013 Endless Mobile, Inc.
+
+const System = imports.system;
+
+function execute(args) {
+ print("%s version %s".format(System.programInvocationName, programVersion));
+}
+
+function summary() {
+ return "Version information";
+}
+
+function help() {
+ print("Prints the version and exits.");
+}