forked from kuzzleio/kourou
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcat.ts
44 lines (36 loc) · 1.07 KB
/
cat.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
import { flags } from '@oclif/command'
import { Client } from '@elastic/elasticsearch'
import { Kommand } from '../../../common'
export default class EsListIndex extends Kommand {
static initSdk = false
static description = 'Lists available ES indexes'
static flags = {
help: flags.help(),
node: flags.string({
char: 'n',
description: 'Elasticsearch server URL',
default: 'http://localhost:9200',
}),
grep: flags.string({
char: 'g',
description: 'Match output with pattern',
}),
}
async runSafe() {
const esClient = new Client({ node: this.flags.node })
try {
const { body } = await esClient.cat.indices({ format: 'json' })
// nice typescript destructuring syntax (:
const indexes: string[] = body
.map(({ index }: { index: string }) => index)
.filter((index: string) => (
this.flags.grep ? index.match(new RegExp(this.flags.grep)) : true
))
.sort()
this.log(JSON.stringify(indexes, null, 2))
}
catch (error) {
console.log(error)
}
}
}