1 | #!/usr/bin/env node
|
2 |
|
3 | const cli = require("commander");
|
4 | const appglue = require("@device.farm/appglue");
|
5 |
|
6 | appglue({ require, file: __dirname + "/../config.json" }).main(async app => {
|
7 |
|
8 | cli
|
9 | .option("-c, --directory [directory]", "change directory");
|
10 |
|
11 | let commandToRun;
|
12 |
|
13 | for (let module of app.commands) {
|
14 | let commands = await module.init(cli);
|
15 | if (!(commands instanceof Array)) {
|
16 | commands = [commands];
|
17 | }
|
18 | for (let command of commands) {
|
19 | command.action((...args) => {
|
20 | commandToRun = async () => {
|
21 | await module.start(command, ...args);
|
22 | };
|
23 | });
|
24 | }
|
25 | }
|
26 |
|
27 | cli.parse(process.argv);
|
28 | if (cli.directory) {
|
29 | process.chdir(cli.directory);
|
30 | }
|
31 |
|
32 | if (commandToRun) {
|
33 | try {
|
34 | await commandToRun();
|
35 | } catch (e) {
|
36 | console.error(e);
|
37 | process.exit(1);
|
38 | }
|
39 | } else {
|
40 | cli.help();
|
41 | process.exit(1);
|
42 | }
|
43 |
|
44 | });
|
45 |
|
46 |
|
47 |
|