-
Notifications
You must be signed in to change notification settings - Fork 115
/
setQueryNodeEndpoint.ts
36 lines (32 loc) · 1.15 KB
/
setQueryNodeEndpoint.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
import chalk from 'chalk'
import ApiCommandBase from '../../base/ApiCommandBase'
import ExitCodes from '../../ExitCodes'
type ApiSetQueryNodeEndpointArgs = { endpoint: string }
export default class ApiSetQueryNodeEndpoint extends ApiCommandBase {
protected requiresApiConnection = false
static description = 'Set query node endpoint'
static args = [
{
name: 'endpoint',
required: false,
description: 'Query node endpoint for the CLI to use',
},
]
async run(): Promise<void> {
const { endpoint }: ApiSetQueryNodeEndpointArgs = this.parse(ApiSetQueryNodeEndpoint)
.args as ApiSetQueryNodeEndpointArgs
let newEndpoint: string | null = null
if (endpoint) {
if (!this.isQueryNodeUriValid(endpoint)) {
this.error('Provided endpoint seems to be incorrect!', { exit: ExitCodes.InvalidInput })
}
newEndpoint = endpoint
} else {
newEndpoint = await this.promptForQueryNodeUri()
}
await this.setPreservedState({ queryNodeUri: newEndpoint })
this.log(
chalk.greenBright('Query node endpoint successfuly changed! New endpoint: ') + chalk.magentaBright(newEndpoint)
)
}
}