-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·129 lines (112 loc) · 2.83 KB
/
Copy pathcli.js
File metadata and controls
executable file
·129 lines (112 loc) · 2.83 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env node
'use strict';
const meow = require('meow');
const logSymbols = require('log-symbols');
const ora = require('ora');
const { runUpgrade } = require('./ibrew/run-upgrade');
const { runRemove } = require('./ibrew/run-remove');
const { runSearch } = require('./ibrew/run-search');
const cli = meow(
`
Usage
$ ibrew [searchterm] [options]
Options
--upgrade, -u Lists installed packages to choose the ones to upgrade
--remove, -r Lists installed packages to choose the ones to uninstall
--size, -s Set number of lines for the interactive lists
--help, -h Show help
--version, -v Print version number
Examples
$ ibrew say
✔ Found 2 packages
? Which package you would like to install? (Use arrow keys)
❯ cowsay
ponysay
$ ibrew --upgrade
✔ Found 3 outdated packages
? Which packages you would like to upgrade? (Press <space> to select, <a> to toggle all, <i> to invert selection)
❯ ◯ git
◯ lynx
◯ watchman
$ ibrew --remove
✔ Found 136 installed packages
? Which packages you would like to uninstall? (Press <space> to select, <a> to toggle all, <i> to invert selection)
❯ ◯ adns
◯ aom
◯ asciinema
`,
{
alias: {
h: 'help',
v: 'version'
},
flags: {
size: {
type: 'string',
alias: 's'
},
upgrade: {
type: 'boolean',
alias: 'u'
},
remove: {
type: 'boolean',
alias: 'r'
}
}
}
);
exports.cli = cli;
const allowedFlags = [
'upgrade',
'u',
'remove',
'r',
'size',
's',
'help',
'h',
'version',
'v'
];
const spinner = ora();
exports.spinner = spinner;
const defaultPageSize = {
searchResult: 10,
installed: 20
};
exports.defaultPageSize = defaultPageSize;
if (cli.input.length === 0 && cli.flags.v === true) {
cli.showVersion();
}
if (cli.input.length === 0 && cli.flags.h === true) {
cli.showHelp(0);
}
if (
cli.input.length > 1 ||
(cli.input.length !== 0 && cli.flags.upgrade === true) ||
!Object.keys(cli.flags).every(flag => allowedFlags.includes(flag))
) {
console.log(
`${logSymbols.error} Invalid input. Please check the help below:`
);
cli.showHelp();
}
// Exits program execution on ESC
process.stdin.on('keypress', (ch, key) => {
if (key && key.name === 'escape') {
process.exit(0);
}
});
// List installed packages to upgrade
if (cli.flags.upgrade === true) {
runUpgrade(Number(cli.flags.size) || defaultPageSize.installed);
}
// List installed packages to remove
if (cli.flags.remove === true) {
runRemove(Number(cli.flags.size) || defaultPageSize.installed);
}
// Search for a package to install
if (cli.flags.upgrade === false && cli.flags.remove === false) {
runSearch(cli.input, Number(cli.flags.size) || defaultPageSize.searchResult);
}