/
cli.js
60 lines (53 loc) 路 1.11 KB
/
cli.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
#!/usr/bin/env node
const path = require("path");
const meow = require("meow");
const { renderApp } = require("./dist/index");
const cli = meow(
`
Usage:
$ yex <options>
Options:
--limit, -l Limit number of items to display.
--copy, -c Copy command to clipboard.
--help, -h Display this message.
--version, -v CLI Version.
Examples:
$ yex
$ yex --limit=5
`,
{
flags: {
limit: {
type: "string",
alias: "l",
},
copy: {
type: "boolean",
alias: "c",
},
help: {
type: "boolean",
alias: "h",
},
version: {
type: "boolean",
alias: "v",
},
},
},
);
try {
require(path.resolve("package.json"));
} catch (err) {
console.log(
"\x1b[31m",
`Error: This doesn't look like a node project. No "package.json" found.`,
);
process.exit(1);
}
if (!cli.flags.hasOwnProperty("limit")) {
const workspaceItemHeight = 3;
const [, terminalHeight] = process.stdout.getWindowSize();
cli.flags.limit = terminalHeight / workspaceItemHeight;
}
renderApp(cli.flags);