Repository navigation
Expand file tree
/
Copy pathstats-reset.ts
More file actions
41 lines (35 loc) · 1.58 KB
/
Copy pathstats-reset.ts
File metadata and controls
41 lines (35 loc) · 1.58 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
import {Command, flags} from '@heroku-cli/command'
import * as color from '@heroku/heroku-cli-util/color'
import {Args, ux} from '@oclif/core'
import tsheredoc from 'tsheredoc'
import ConfirmCommand from '../../lib/confirm-command.js'
import redisApi, {RedisApiResponse} from '../../lib/redis/api.js'
const heredoc = tsheredoc
export default class StatsReset extends Command {
static args = {
database: Args.string({description: 'name of the Key-Value Store database. If omitted, it defaults to the primary database associated with the app.'}),
}
static description = 'reset all stats covered by RESETSTAT (https://redis.io/commands/config-resetstat)'
static flags = {
app: flags.app({required: true}),
confirm: flags.string({char: 'c'}),
remote: flags.remote(),
}
static topic = 'redis'
public async run(): Promise<void> {
const {args, flags} = await this.parse(StatsReset)
const {app, confirm} = flags
const {database} = args
const addon = await redisApi(app, database, false, this.heroku).getRedisAddon()
const warning = heredoc(`
WARNING: Irreversible action.
All stats covered by RESETSTAT will be reset on ${color.addon(addon.name || '')}.
`)
const confirmCommand = new ConfirmCommand()
await confirmCommand.confirm(app, confirm, warning)
ux.action.start(`Resetting stats on ${color.addon(addon.name || '')}`)
const {body: response} = await redisApi(app, database, false, this.heroku)
.request<RedisApiResponse>(`/redis/v0/databases/${addon.id}/stats/reset`, 'POST', {})
ux.action.stop(response.message)
}
}