1 | #!/usr/bin/env node
|
2 |
|
3 | const cli = require('commander')
|
4 | const pkg = require('./package.json')
|
5 | const cfg = require('./lib/config')
|
6 | const core = require('./core')
|
7 |
|
8 | cli.version(pkg.version).usage('<command> [option] <addon ...>')
|
9 |
|
10 | cli
|
11 | .command('add <addons...>')
|
12 | .description('install one or more addons locally')
|
13 | .alias('install')
|
14 | .option('--anyway', 'install latest addon release for _classic_ mode anyway')
|
15 | .action((aa, cmd) => {
|
16 | cfg.anyway(cmd.anyway)
|
17 | core.add(aa)
|
18 | })
|
19 |
|
20 | cli
|
21 | .command('rm <addon...>')
|
22 | .description('remove addons from local installation')
|
23 | .alias('delete')
|
24 | .action(key => core.rm(key))
|
25 |
|
26 | cli
|
27 | .command('search <text>')
|
28 | .description('search addons whose name contain <text>')
|
29 | .option(
|
30 | '--anyway',
|
31 | 'search for latest addon release for _classic_ mode anyway'
|
32 | )
|
33 | .action((text, cmd) => {
|
34 | cfg.anyway(cmd.anyway)
|
35 | core.search(text)
|
36 | })
|
37 |
|
38 | cli
|
39 | .command('ls')
|
40 | .description('list all installed addons')
|
41 | .option('-l, --long', 'show detailed addon information')
|
42 | .option('-t, --time', 'sort by updated time')
|
43 | .alias('list')
|
44 | .action(core.ls)
|
45 |
|
46 | cli
|
47 | .command('info <addon>')
|
48 | .description(
|
49 | 'show info of an addon, the addon does not have to be an installed locally'
|
50 | )
|
51 | .option(
|
52 | '--anyway',
|
53 | 'show info of latest addon release for _classic_ mode anyway'
|
54 | )
|
55 | .action((ad, cmd) => {
|
56 | cfg.anyway(cmd.anyway)
|
57 | core.info(ad)
|
58 | })
|
59 |
|
60 | cli
|
61 | .command('update')
|
62 | .description('update all installed addons')
|
63 | .option('--anyway', 'update latest addon release for _classic_ mode anyway')
|
64 | .option(
|
65 | '--db',
|
66 | 'for update addon database, no addon will be updated if this option is specified'
|
67 | )
|
68 | .action(cmd => {
|
69 | cfg.anyway(cmd.anyway)
|
70 | core.update(cli.args.length > 1 ? cli.args.slice(0, -1) : null, cmd)
|
71 | })
|
72 |
|
73 | cli
|
74 | .command('import')
|
75 | .description('import local addons')
|
76 | .action(() => core.pickup())
|
77 |
|
78 | cli
|
79 | .command('switch')
|
80 | .alias('sw')
|
81 | .description('switch mode between retail and classic')
|
82 | .action(core.switch)
|
83 |
|
84 | cli
|
85 | .command('restore [repo]')
|
86 | .description(
|
87 | 'restore addons from github repo, only <org/repo> is required, not the full URL. (e.g. antiwinter/wowui)'
|
88 | )
|
89 | .option(
|
90 | '-f, --full',
|
91 | 'not only restore addons, but also restore addons settings'
|
92 | )
|
93 | .action(repo => core.restore(repo))
|
94 |
|
95 | cli.on('command:*', () => {
|
96 | cli.help()
|
97 | })
|
98 |
|
99 | if (process.argv.length < 3) return cli.help()
|
100 |
|
101 |
|
102 |
|
103 | if (!cfg.checkPath()) return
|
104 |
|
105 | core.checkUpdate(() => {
|
106 | cli.parse(process.argv)
|
107 | })
|