Skip to content

Commit

Permalink
feat: add quiet flag (#621)
Browse files Browse the repository at this point in the history
Signed-off-by: Jeffrey Tang <[email protected]>
  • Loading branch information
JeffreyDallas authored Sep 30, 2024
1 parent 5fa1b7d commit b068c8f
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 17 deletions.
14 changes: 14 additions & 0 deletions src/commands/flags.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,19 @@ export const adminKey = {
}

/** @type {CommandFlag} **/
export const quiet = {
constName: 'quiet',
name: 'quiet-mode',
definition: {
describe: 'Quiet mode, do not prompt for confirmation',
defaultValue: false,
alias: 'q',
type: 'boolean',
disablePrompt: true
}
}

/** @type {CommandFlag[]} **/
export const mirrorNodeVersion = {
constName: 'mirrorNodeVersion',
name: 'mirror-node-version',
Expand All @@ -765,6 +778,7 @@ export const mirrorNodeVersion = {
type: 'string'
}
}

/** @type {CommandFlag[]} **/
export const allFlags = [
accountId,
Expand Down
1 change: 1 addition & 0 deletions src/commands/mirror_node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class MirrorNodeCommand extends BaseCommand {
flags.namespace,
flags.profileFile,
flags.profileName,
flags.quiet,
flags.tlsClusterIssuerType,
flags.valuesFile,
flags.mirrorNodeVersion
Expand Down
1 change: 1 addition & 0 deletions src/commands/network.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class NetworkCommand extends BaseCommand {
flags.persistentVolumeClaims,
flags.profileFile,
flags.profileName,
flags.quiet,
flags.releaseTag,
flags.settingTxt,
flags.valuesFile
Expand Down
40 changes: 33 additions & 7 deletions src/commands/node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,30 @@ export class NodeCommand extends BaseCommand {
]
}

/**
* @returns {CommandFlag[]}
*/
static get START_FLAGS_LIST () {
return [
flags.app,
flags.debugNodeId,
flags.namespace,
flags.nodeIDs,
flags.quiet
]
}

/**
* @returns {CommandFlag[]}
*/
static get STOP_FLAGS_LIST () {
return [
flags.namespace,
flags.nodeIDs,
flags.quiet
]
}

/**
* @returns {string}
*/
Expand All @@ -128,7 +152,8 @@ export class NodeCommand extends BaseCommand {
flags.devMode,
flags.generateGossipKeys,
flags.generateTlsKeys,
flags.nodeIDs
flags.nodeIDs,
flags.quiet
]
}

Expand All @@ -150,6 +175,7 @@ export class NodeCommand extends BaseCommand {
flags.localBuildPath,
flags.namespace,
flags.nodeIDs,
flags.quiet,
flags.releaseTag
]
}
Expand Down Expand Up @@ -179,6 +205,7 @@ export class NodeCommand extends BaseCommand {
flags.gossipEndpoints,
flags.grpcEndpoints,
flags.localBuildPath,
flags.quiet,
flags.namespace,
flags.releaseTag
]
Expand Down Expand Up @@ -244,6 +271,7 @@ export class NodeCommand extends BaseCommand {
flags.localBuildPath,
flags.namespace,
flags.nodeID,
flags.quiet,
flags.releaseTag
]
}
Expand All @@ -270,6 +298,7 @@ export class NodeCommand extends BaseCommand {
flags.newAccountNumber,
flags.newAdminKey,
flags.nodeID,
flags.quiet,
flags.releaseTag,
flags.tlsPrivateKey,
flags.tlsPublicKey
Expand Down Expand Up @@ -1143,6 +1172,7 @@ export class NodeCommand extends BaseCommand {
title: 'Initialize',
task: async (ctx, task) => {
self.configManager.update(argv)

await prompts.execute(task, self.configManager, [
flags.namespace,
flags.nodeIDs
Expand Down Expand Up @@ -2391,10 +2421,7 @@ export class NodeCommand extends BaseCommand {
command: 'start',
desc: 'Start a node',
builder: y => flags.setCommandFlags(y,
flags.app,
flags.debugNodeId,
flags.namespace,
flags.nodeIDs
NodeCommand.START_FLAGS_LIST
),
handler: argv => {
nodeCmd.logger.debug('==== Running \'node start\' ===')
Expand All @@ -2413,8 +2440,7 @@ export class NodeCommand extends BaseCommand {
command: 'stop',
desc: 'Stop a node',
builder: y => flags.setCommandFlags(y,
flags.namespace,
flags.nodeIDs
NodeCommand.STOP_FLAGS_LIST
),
handler: argv => {
nodeCmd.logger.debug('==== Running \'node stop\' ===')
Expand Down
3 changes: 3 additions & 0 deletions src/commands/prompts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,9 @@ export async function execute (task, configManager, flagList = []) {
}

const prompt = prompts.get(flag.name)
if (configManager.getFlag(flags.quiet)) {
return
}
const input = await prompt(task, configManager.getFlag(flag))
configManager.setFlag(flag, input)
}
Expand Down
18 changes: 13 additions & 5 deletions src/commands/relay.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,24 @@ export class RelayCommand extends BaseCommand {
flags.operatorKey,
flags.profileFile,
flags.profileName,
flags.quiet,
flags.relayReleaseTag,
flags.replicaCount,
flags.valuesFile
]
}

/**
* @returns {CommandFlag[]}
*/
static get DESTROY_FLAGS_LIST () {
return [
flags.chartDirectory,
flags.namespace,
flags.nodeIDs
]
}

/**
* @param {string} valuesFile
* @param {string[]} nodeIDs
Expand Down Expand Up @@ -301,11 +313,7 @@ export class RelayCommand extends BaseCommand {
self.configManager.setFlag(flags.nodeIDs, '')

self.configManager.update(argv)
await prompts.execute(task, self.configManager, [
flags.chartDirectory,
flags.namespace,
flags.nodeIDs
])
await prompts.execute(task, self.configManager, RelayCommand.DESTROY_FLAGS_LIST)

// prompt if inputs are empty and set it in the context
ctx.config = {
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/commands/mirror_node.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe('MirrorNodeCommand', () => {
argv[flags.relayReleaseTag.name] = flags.relayReleaseTag.definition.defaultValue
// set the env variable SOLO_FST_CHARTS_DIR if developer wants to use local FST charts
argv[flags.chartDirectory.name] = process.env.SOLO_FST_CHARTS_DIR ? process.env.SOLO_FST_CHARTS_DIR : undefined
argv[flags.quiet.name] = true

const bootstrapResp = bootstrapNetwork(testName, argv)
const k8 = bootstrapResp.opts.k8
Expand Down Expand Up @@ -99,6 +100,7 @@ describe('MirrorNodeCommand', () => {
flags.hederaExplorerTlsLoadBalancerIp.constName,
flags.profileFile.constName,
flags.profileName.constName,
flags.quiet.constName,
flags.tlsClusterIssuerType.constName
])
}, 600_000)
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/commands/network.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('NetworkCommand', () => {
argv[flags.applicationEnv.name] = applicationEnvFilePath
// set the env variable SOLO_FST_CHARTS_DIR if developer wants to use local FST charts
argv[flags.chartDirectory.name] = process.env.SOLO_FST_CHARTS_DIR ? process.env.SOLO_FST_CHARTS_DIR : undefined
argv[flags.quiet.name] = true

const bootstrapResp = bootstrapTestVariables(testName, argv)
const k8 = bootstrapResp.opts.k8
Expand Down Expand Up @@ -106,6 +107,7 @@ describe('NetworkCommand', () => {
flags.log4j2Xml.constName,
flags.profileFile.constName,
flags.profileName.constName,
flags.quiet.constName,
flags.settingTxt.constName
])
} catch (e) {
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/commands/node_delete.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('Node delete', () => {
argv[flags.chartDirectory.name] = process.env.SOLO_FST_CHARTS_DIR ? process.env.SOLO_FST_CHARTS_DIR : undefined
argv[flags.releaseTag.name] = HEDERA_PLATFORM_VERSION_TAG
argv[flags.namespace.name] = namespace
argv[flags.quiet.name] = true
const bootstrapResp = bootstrapNetwork(namespace, argv)
const nodeCmd = bootstrapResp.cmd.nodeCmd
const accountCmd = bootstrapResp.cmd.accountCmd
Expand All @@ -62,7 +63,8 @@ describe('Node delete', () => {
expect(nodeCmd.getUnusedConfigs(NodeCommand.DELETE_CONFIGS_NAME)).toEqual([
flags.app.constName,
flags.devMode.constName,
flags.endpointType.constName
flags.endpointType.constName,
flags.quiet.constName
])

await nodeCmd.accountManager.close()
Expand Down
1 change: 1 addition & 0 deletions test/e2e/commands/node_local_hedera.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('Node local build', () => {
argv[flags.clusterName.name] = TEST_CLUSTER
// set the env variable SOLO_FST_CHARTS_DIR if developer wants to use local FST charts
argv[flags.chartDirectory.name] = process.env.SOLO_FST_CHARTS_DIR ? process.env.SOLO_FST_CHARTS_DIR : undefined
argv[flags.quiet.name] = true

let hederaK8
afterAll(async () => {
Expand Down
1 change: 1 addition & 0 deletions test/e2e/commands/node_local_ptt.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('Node local build', () => {
argv[flags.clusterName.name] = TEST_CLUSTER
// set the env variable SOLO_FST_CHARTS_DIR if developer wants to use local FST charts
argv[flags.chartDirectory.name] = process.env.SOLO_FST_CHARTS_DIR ? process.env.SOLO_FST_CHARTS_DIR : undefined
argv[flags.quiet.name] = true

let pttK8
afterAll(async () => {
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/commands/node_update.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe('Node update', () => {
argv[flags.releaseTag.name] = HEDERA_PLATFORM_VERSION_TAG
argv[flags.namespace.name] = namespace
argv[flags.persistentVolumeClaims.name] = true
argv[flags.quiet.name] = true
const bootstrapResp = bootstrapNetwork(namespace, argv)
const nodeCmd = bootstrapResp.cmd.nodeCmd
const accountCmd = bootstrapResp.cmd.accountCmd
Expand Down Expand Up @@ -91,7 +92,8 @@ describe('Node update', () => {
await nodeCmd.update(argv)
expect(nodeCmd.getUnusedConfigs(NodeCommand.UPDATE_CONFIGS_NAME)).toEqual([
flags.app.constName,
flags.devMode.constName
flags.devMode.constName,
flags.quiet.constName
])
await nodeCmd.accountManager.close()
}, 1800000)
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/commands/relay.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describe('RelayCommand', () => {
argv[flags.fstChartVersion.name] = version.FST_CHART_VERSION
argv[flags.force.name] = true
argv[flags.relayReleaseTag.name] = flags.relayReleaseTag.definition.defaultValue
argv[flags.quiet.name] = true

const bootstrapResp = bootstrapNetwork(testName, argv)
const k8 = bootstrapResp.opts.k8
Expand Down Expand Up @@ -79,7 +80,8 @@ describe('RelayCommand', () => {
}
expect(relayCmd.getUnusedConfigs(RelayCommand.DEPLOY_CONFIGS_NAME)).toEqual([
flags.profileFile.constName,
flags.profileName.constName
flags.profileName.constName,
flags.quiet.constName
])
await sleep(500)

Expand Down
2 changes: 2 additions & 0 deletions test/e2e/commands/separate_node_add.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('Node add via separated commands should success', () => {
argv[flags.namespace.name] = namespace
argv[flags.force.name] = true
argv[flags.persistentVolumeClaims.name] = true
argv[flags.quiet.name] = true

const argvPrepare = Object.assign({}, argv)

Expand Down Expand Up @@ -87,6 +88,7 @@ describe('Node add via separated commands should success', () => {
flags.generateTlsKeys.constName,
flags.gossipEndpoints.constName,
flags.grpcEndpoints.constName,
flags.quiet.constName,
flags.adminKey.constName,
'curDate',
'freezeAdminPrivateKey'
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/e2e_node_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export function e2eNodeKeyRefreshTest (testName, mode, releaseTag = HEDERA_PLATF
argv[flags.chartDirectory.name] = process.env.SOLO_FST_CHARTS_DIR
? process.env.SOLO_FST_CHARTS_DIR
: undefined
argv[flags.quiet.name] = true

const bootstrapResp = bootstrapNetwork(testName, argv)
const accountManager = bootstrapResp.opts.accountManager
Expand Down Expand Up @@ -149,7 +150,8 @@ export function e2eNodeKeyRefreshTest (testName, mode, releaseTag = HEDERA_PLATF
await expect(nodeCmd.refresh(argv)).resolves.toBeTruthy()
expect(nodeCmd.getUnusedConfigs(
NodeCommand.REFRESH_CONFIGS_NAME)).toEqual(
[flags.devMode.constName])
[flags.devMode.constName,
flags.quiet.constName])
} catch (e) {
nodeCmd.logger.showUserError(e)
expect(e).toBeNull()
Expand Down
2 changes: 2 additions & 0 deletions test/test_add.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function testNodeAdd (localBuildPath
argv[flags.force.name] = true
argv[flags.persistentVolumeClaims.name] = true
argv[flags.localBuildPath.name] = localBuildPath
argv[flags.quiet.name] = true

const bootstrapResp = bootstrapNetwork(namespace, argv)
const nodeCmd = bootstrapResp.cmd.nodeCmd
Expand Down Expand Up @@ -79,6 +80,7 @@ export function testNodeAdd (localBuildPath
flags.app.constName,
flags.chainId.constName,
flags.devMode.constName,
flags.quiet.constName,
flags.adminKey.constName
])
await nodeCmd.accountManager.close()
Expand Down
4 changes: 3 additions & 1 deletion test/test_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ export function bootstrapNetwork (testName, argv,
await expect(nodeCmd.keys(argv)).resolves.toBeTruthy()
expect(nodeCmd.getUnusedConfigs(NodeCommand.KEYS_CONFIGS_NAME)).toEqual([
flags.cacheDir.constName,
flags.devMode.constName
flags.devMode.constName,
flags.quiet.constName
])
}, 120000)

Expand All @@ -241,6 +242,7 @@ export function bootstrapNetwork (testName, argv,
flags.log4j2Xml.constName,
flags.profileFile.constName,
flags.profileName.constName,
flags.quiet.constName,
flags.settingTxt.constName
])
}, 180000)
Expand Down

0 comments on commit b068c8f

Please sign in to comment.