-
Notifications
You must be signed in to change notification settings - Fork 39
/
index.js
107 lines (85 loc) · 2.3 KB
/
index.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#! /usr/bin/env node
const opts = require('minimist')(process.argv.slice(2), {
string: ['foo', 'bar'],
boolean: ['help', 'version', 'loglevel']
});
const tabtab = require('../..');
const args = opts._;
const completion = env => {
if (!env.complete) return;
if (env.prev === 'someCommand') {
return tabtab.log(['is', 'this', 'the', 'real', 'life']);
}
if (env.prev === 'anotherOne') {
return tabtab.log(['is', 'this', 'just', 'fantasy']);
}
if (env.prev === '--loglevel') {
return tabtab.log(['error', 'warn', 'info', 'notice', 'verbose']);
}
return tabtab.log([
'--help',
'--version',
'--loglevel',
'foo',
'bar',
'install-completion',
'uninstall-completion',
'completion',
'someCommand:someCommand is a some kind of command with a description',
{
name: 'someOtherCommand:hey',
description: 'You must add a description for items with ":" in them'
},
'anotherOne'
]);
};
const init = async () => {
const cmd = args[0];
if (opts.help) {
return console.log('Output help here');
}
if (opts.version) {
return console.log('Output version here');
}
if (opts.loglevel) {
return console.log('Output version here');
}
if (cmd === 'foo') {
return console.log('foobar');
}
if (cmd === 'bar') {
return console.log('barbar');
}
if (cmd === 'someCommand') {
return console.log('is this the real life ?');
}
if (cmd === 'anotherOne') {
return console.log('is this just fantasy ?');
}
if (cmd === 'install-completion') {
// Here we install for the program `tabtab-test` (this file), with
// completer being the same program. Sometimes, you want to complete
// another program that's where the `completer` option might come handy.
await tabtab
.install({
name: 'tabtab-test',
completer: 'tabtab-test'
})
.catch(err => console.error('INSTALL ERROR', err));
return;
}
if (cmd === 'uninstall-completion') {
// Here we uninstall for the program `tabtab-test` (this file).
await tabtab
.uninstall({
name: 'tabtab-test'
})
.catch(err => console.error('UNINSTALL ERROR', err));
return;
}
if (cmd === 'completion') {
const env = tabtab.parseEnv(process.env);
return completion(env);
}
};
init();