Skip to content

Commit 33f6be9

Browse files
Change scale to scale:set, add scale:get
1 parent 69b3542 commit 33f6be9

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

src/commands/scale/get.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {Command, Flags} from '@oclif/core'
2+
3+
import {getDisco} from '../../config.js'
4+
import {request} from '../../auth-request.js'
5+
6+
export default class ScaleGet extends Command {
7+
static override args = {}
8+
9+
static strict = false
10+
11+
static override description = 'get current scale (number of replicas) for all services of a project'
12+
13+
static override examples = [
14+
'<%= config.bin %> <%= command.id %> --project mysite',
15+
]
16+
17+
static override flags = {
18+
project: Flags.string({required: true}),
19+
disco: Flags.string({required: false}),
20+
}
21+
22+
public async run(): Promise<void> {
23+
const {flags} = await this.parse(ScaleGet)
24+
const discoConfig = getDisco(flags.disco || null)
25+
const url = `https://${discoConfig.host}/api/projects/${flags.project}/scale`
26+
27+
const res = await request({method: 'GET', url, discoConfig})
28+
const respBody = (await res.json()) as {services: {name: string; scale: number}[]}
29+
for (const service of respBody.services) {
30+
this.log(`${service.name}=${service.scale}`)
31+
}
32+
}
33+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {Args, Command, Flags} from '@oclif/core'
22

3-
import {getDisco} from '../config.js'
4-
import {request} from '../auth-request.js'
3+
import {getDisco} from '../../config.js'
4+
import {request} from '../../auth-request.js'
55

6-
export default class Scale extends Command {
6+
export default class ScaleSet extends Command {
77
static override args = {
88
services: Args.string({
99
description: 'service or services to scale and number of replicas, e.g. web=3',
@@ -26,7 +26,7 @@ export default class Scale extends Command {
2626
}
2727

2828
public async run(): Promise<void> {
29-
const {argv, flags} = await this.parse(Scale)
29+
const {argv, flags} = await this.parse(ScaleSet)
3030
const discoConfig = getDisco(flags.disco || null)
3131
const url = `https://${discoConfig.host}/api/projects/${flags.project}/scale`
3232
const reqBody = {services: {}} as Record<string, Record<string, number>>

0 commit comments

Comments
 (0)