From c2bdffa3b86c15b79c1a85f2d4cf17d8990c7a7b Mon Sep 17 00:00:00 2001 From: Lenin Mehedy Date: Fri, 1 Dec 2023 13:56:20 +1100 Subject: [PATCH] fix: boolean flags handling Signed-off-by: Lenin Mehedy --- .../src/commands/cluster.mjs | 22 ++++++++----------- .../src/commands/flags.mjs | 1 + .../src/commands/prompts.mjs | 4 ++-- .../src/core/config_manager.mjs | 2 +- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/fullstack-network-manager/src/commands/cluster.mjs b/fullstack-network-manager/src/commands/cluster.mjs index fb96882c8..d74969b1d 100644 --- a/fullstack-network-manager/src/commands/cluster.mjs +++ b/fullstack-network-manager/src/commands/cluster.mjs @@ -201,6 +201,7 @@ export class ClusterCommand extends BaseCommand { title: 'Initialize', task: async (ctx, task) => { const cachedConfig = await self.configManager.setupConfig(argv) + self.logger.debug('Setup cached config', { cachedConfig, argv }) // extract config values const clusterName = self.configManager.flagValue(cachedConfig, flags.clusterName) @@ -228,6 +229,8 @@ export class ClusterCommand extends BaseCommand { deployCertManagerCRDs: await prompts.promptDeployCertManagerCRDs(task, deployCertManagerCRDs, namespaces) } + self.logger.debug('Prepare ctx.config', { config: ctx.config, argv }) + ctx.isChartInstalled = await this.chartManager.isChartInstalled(ctx.config.namespace, constants.CHART_FST_SETUP_NAME) } }, @@ -334,8 +337,7 @@ export class ClusterCommand extends BaseCommand { desc: 'Create a cluster', builder: y => flags.setCommandFlags(y, flags.clusterName, flags.namespace), handler: argv => { - clusterCmd.logger.debug("==== Running 'cluster create' ===") - clusterCmd.logger.debug(argv) + clusterCmd.logger.debug("==== Running 'cluster create' ===", { argv }) clusterCmd.create(argv).then(r => { clusterCmd.logger.debug('==== Finished running `cluster create`====') @@ -352,8 +354,7 @@ export class ClusterCommand extends BaseCommand { desc: 'Delete a cluster', builder: y => flags.setCommandFlags(y, flags.clusterName), handler: argv => { - clusterCmd.logger.debug("==== Running 'cluster delete' ===") - clusterCmd.logger.debug(argv) + clusterCmd.logger.debug("==== Running 'cluster delete' ===", { argv }) clusterCmd.delete(argv).then(r => { clusterCmd.logger.debug('==== Finished running `cluster delete`====') @@ -369,8 +370,7 @@ export class ClusterCommand extends BaseCommand { command: 'list', desc: 'List all clusters', handler: argv => { - clusterCmd.logger.debug("==== Running 'cluster list' ===") - clusterCmd.logger.debug(argv) + clusterCmd.logger.debug("==== Running 'cluster list' ===", { argv }) clusterCmd.showClusterList().then(r => { clusterCmd.logger.debug('==== Finished running `cluster list`====') @@ -387,9 +387,7 @@ export class ClusterCommand extends BaseCommand { desc: 'Get cluster info', builder: y => flags.setCommandFlags(y, flags.clusterName), handler: argv => { - clusterCmd.logger.debug("==== Running 'cluster info' ===") - clusterCmd.logger.debug(argv) - + clusterCmd.logger.debug("==== Running 'cluster info' ===", { argv }) clusterCmd.getClusterInfo(argv).then(r => { clusterCmd.logger.debug('==== Finished running `cluster info`====') @@ -414,8 +412,7 @@ export class ClusterCommand extends BaseCommand { flags.deployCertManagerCRDs ), handler: argv => { - clusterCmd.logger.debug("==== Running 'cluster setup' ===") - clusterCmd.logger.debug(argv) + clusterCmd.logger.debug("==== Running 'cluster setup' ===", { argv }) clusterCmd.setup(argv).then(r => { clusterCmd.logger.debug('==== Finished running `cluster setup`====') @@ -435,8 +432,7 @@ export class ClusterCommand extends BaseCommand { flags.namespace ), handler: argv => { - clusterCmd.logger.debug("==== Running 'cluster reset' ===") - clusterCmd.logger.debug(argv) + clusterCmd.logger.debug("==== Running 'cluster reset' ===", { argv }) clusterCmd.reset(argv).then(r => { clusterCmd.logger.debug('==== Finished running `cluster reset`====') diff --git a/fullstack-network-manager/src/commands/flags.mjs b/fullstack-network-manager/src/commands/flags.mjs index a282ee345..c76efd2b4 100644 --- a/fullstack-network-manager/src/commands/flags.mjs +++ b/fullstack-network-manager/src/commands/flags.mjs @@ -221,6 +221,7 @@ export const allFlags = [ deployPrometheusStack, deployMinio, deployEnvoyGateway, + deployCertManager, deployCertManagerCRDs, releaseTag, cacheDir, diff --git a/fullstack-network-manager/src/commands/prompts.mjs b/fullstack-network-manager/src/commands/prompts.mjs index 0f2127682..d3a6993e2 100644 --- a/fullstack-network-manager/src/commands/prompts.mjs +++ b/fullstack-network-manager/src/commands/prompts.mjs @@ -236,7 +236,7 @@ export async function promptDeployEnvoyGateway (task, input) { export async function promptDeployCertManager (task, input) { try { - if (input === undefined) { + if (typeof input !== 'boolean') { input = await task.prompt(ListrEnquirerPromptAdapter).run({ type: 'toggle', default: flags.deployCertManager.definition.default, @@ -252,7 +252,7 @@ export async function promptDeployCertManager (task, input) { export async function promptDeployCertManagerCRDs (task, input) { try { - if (input === undefined) { + if (typeof input !== 'boolean') { input = await task.prompt(ListrEnquirerPromptAdapter).run({ type: 'toggle', default: flags.deployCertManagerCRDs.definition.default, diff --git a/fullstack-network-manager/src/core/config_manager.mjs b/fullstack-network-manager/src/core/config_manager.mjs index 46d898d87..a10042eac 100644 --- a/fullstack-network-manager/src/core/config_manager.mjs +++ b/fullstack-network-manager/src/core/config_manager.mjs @@ -30,7 +30,7 @@ export class ConfigManager { } hasFlag (config, flag) { - return !!config.flags[flag.name] + return config.flags[flag.name] !== undefined } flagValue (config, flag) {