-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
107 lines (94 loc) · 2.73 KB
/
index.ts
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
import * as files from './lib/files';
import * as program from 'commander';
import { Human, GroupCode } from "./types";
import { outputTldr, findHumansByGroupCode, echoShikai, echoBankai } from "./lib/output";
// バージョン情報
program
.version('0.0.1', '-V, --version')
program
.command('human')
.alias('hu')
.description('Output human names')
.option("-a, --all", "List all")
.option("-g, --gotei13", "List gotei 13")
.option("-e, --espada", "List espada")
.option("-v, --visored", "List visored")
.option("-k, --karakuracho", "List karakuracho")
.option("-f, --fullbringer", "List fullbringer")
.action( async (cmd, options) => {
const dataList: Human[] = await files.getHumanDataList()
let targetCode: GroupCode = 'all'
if (cmd.gotei13) {
targetCode = 'gotei13'
}
if (cmd.espada) {
targetCode = 'espada'
}
if (cmd.visored) {
targetCode = 'visored'
}
if (cmd.karakuracho) {
targetCode = 'karakuracho'
}
if (cmd.fullbringer) {
targetCode = 'fullbringer'
}
const humans = findHumansByGroupCode(dataList, targetCode, options)
if (humans.length === 0) {
console.log('No matching')
return
}
humans.forEach(human => console.log(human.name))
})
.on('--help', function() {
console.log('\n Examples:')
console.log()
console.log(' $ blch human --gotei13')
console.log(' $ blch hu -g')
console.log()
})
program
.command('tldr <target>')
.alias('tl')
.description('Output character tldr')
.action( async (target, options) => {
const dataList: Human[] = await files.getHumanDataList()
const humans = dataList.filter(el => el.name == target)
if (humans.length === 0) {
console.log('No matching')
return
}
outputTldr(humans[0])
}).on('--help', function() {
console.log('\n Examples:')
console.log()
console.log(' $ blch tldr 黒崎一護')
console.log()
})
program
.command('echo <target>')
.alias('e')
.option("-s, --shikai", "echo shikai")
.option("-b, --bankai", "echo bankai")
.description('echo shikai, bankai')
.action( async (target, options) => {
const dataList: Human[] = await files.getHumanDataList()
const humans = dataList.filter(el => el.name == target)
if (humans.length === 0) {
console.log('No matching')
return
}
if (options.shikai) {
echoShikai(humans[0])
} else if (options.bankai) {
echoBankai(humans[0])
}
}).on('--help', function() {
console.log('\n Examples:')
console.log()
console.log(' $ blch echo --shikai 朽木白哉')
console.log(' $ blch echo --bankai 黒崎一護')
console.log()
})
program.parse(process.argv)