summaryrefslogtreecommitdiff
path: root/tools/eos-application-manifest/eos-application-manifest.in
blob: 382693bd109c0fbf099aa8f9d5cde33344a416e7 (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
#!/usr/bin/gjs
// Copyright 2013 Endless Mobile, Inc.

const Format = imports.format;
const System = imports.system;

String.prototype.format = Format.format;
// monkeypatch System.programInvocationName which is not in this version of GJS
System.programInvocationName = 'eos-application-manifest';

// Other constants, available from subcommands' code
const commandSearchPath = "@libexecdir@/eos-application-manifest/commands";
const programVersion = "@PACKAGE_VERSION@";

// Import commands from commands/ directory (local first)
imports.searchPath.unshift(commandSearchPath);
imports.searchPath.unshift('./commands');

// Must invoke a subcommand
if (ARGV.length === 0) {
    // automatically invoke "help" command with no arguments
    const Help = imports.help;
    Help.execute([]);
    // System.exit(1); broken, bugzilla.gnome.org #703826
    throw new Error();
}

let command_name = ARGV.shift();
let command;
try {
    command = imports[command_name];
} catch (e) {
    if (/No JS module '.*' found in search path/.test(e.message)) {
        let program_name = System.programInvocationName;
        printerr("%s: '%s' is not a valid command name. See %s help.".format(
            program_name, command_name, program_name));
        // System.exit(1); broken
        throw new Error();
    }
}
try {
    command.execute(ARGV);
} catch (e) {
    printerr('%s: %s'.format(System.programInvocationName, e.message));
    // System.exit(1); broken
    throw e;
}