Skip to content

Commit

Permalink
changed strategy to override values on argv so they have effect durin…
Browse files Browse the repository at this point in the history
…g the post middleware command execution

Signed-off-by: instamenta <[email protected]>
  • Loading branch information
instamenta committed Jan 22, 2025
1 parent c354941 commit 1e270e1
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/commands/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export class AccountCommand extends BaseCommand {
{
title: 'Initialize',
task: async (ctx, task) => {
self.configManager.update(argv);
await self.configManager.executePrompt(task, [flags.namespace]);

const config = {
Expand Down Expand Up @@ -329,6 +330,7 @@ export class AccountCommand extends BaseCommand {
{
title: 'Initialize',
task: async (ctx, task) => {
self.configManager.update(argv);
await self.configManager.executePrompt(task, [flags.namespace]);

const config = {
Expand Down Expand Up @@ -411,6 +413,7 @@ export class AccountCommand extends BaseCommand {
{
title: 'Initialize',
task: async (ctx, task) => {
self.configManager.update(argv);
await self.configManager.executePrompt(task, [flags.accountId, flags.namespace]);

const config = {
Expand Down Expand Up @@ -493,6 +496,7 @@ export class AccountCommand extends BaseCommand {
{
title: 'Initialize',
task: async (ctx, task) => {
self.configManager.update(argv);
await self.configManager.executePrompt(task, [flags.accountId, flags.namespace]);

const config = {
Expand Down
1 change: 1 addition & 0 deletions src/commands/cluster/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const connectConfigBuilder = async function (argv, ctx, task) {
export const setupConfigBuilder = async function (argv, ctx, task) {
const parent = this.parent;
const configManager = parent.getConfigManager();
configManager.update(argv);
flags.disablePrompts([flags.chartDirectory]);

await configManager.executePrompt(task, [
Expand Down
5 changes: 4 additions & 1 deletion src/commands/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class DeploymentCommand extends BaseCommand {
{
title: 'Initialize',
task: async (ctx, task) => {
self.configManager.update(argv);
self.logger.debug('Updated config with argv', {config: self.configManager.config});

await self.configManager.executePrompt(task, [
Expand Down Expand Up @@ -137,7 +138,9 @@ export class DeploymentCommand extends BaseCommand {

for (const context of Object.keys(ctx.config.contextCluster)) {
const cluster = ctx.config.contextCluster[context];
subTasks.push(RemoteConfigTasks.createRemoteConfig.bind(this)(cluster, context, ctx.config.namespace));
subTasks.push(
RemoteConfigTasks.createRemoteConfig.bind(this)(cluster, context, ctx.config.namespace, argv),
);
}

return task.newListr(subTasks, {
Expand Down
1 change: 1 addition & 0 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class InitCommand extends BaseCommand {
{
title: 'Setup home directory and cache',
task: ctx => {
self.configManager.update(argv);
ctx.dirs = this.setupHomeDirectory();
},
},
Expand Down
3 changes: 3 additions & 0 deletions src/commands/mirror_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ export class MirrorNodeCommand extends BaseCommand {
{
title: 'Initialize',
task: async (ctx, task) => {
self.configManager.update(argv);

// disable the prompts that we don't want to prompt the user for
flags.disablePrompts([
flags.deployHederaExplorer,
Expand Down Expand Up @@ -598,6 +600,7 @@ export class MirrorNodeCommand extends BaseCommand {
}
}

self.configManager.update(argv);
await self.configManager.executePrompt(task, [flags.namespace]);

// @ts-ignore
Expand Down
2 changes: 2 additions & 0 deletions src/commands/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ export class NetworkCommand extends BaseCommand {
}

async prepareConfig(task: any, argv: any) {
this.configManager.update(argv);
this.logger.debug('Updated config with argv', {config: this.configManager.config});

// disable the prompts that we don't want to prompt the user for
Expand Down Expand Up @@ -749,6 +750,7 @@ export class NetworkCommand extends BaseCommand {
}
}

self.configManager.update(argv);
await self.configManager.executePrompt(task, [flags.deletePvcs, flags.deleteSecrets, flags.namespace]);

ctx.config = {
Expand Down
2 changes: 2 additions & 0 deletions src/commands/node/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1738,6 +1738,8 @@ export class NodeCommandTasks {
this.logger.setDevMode(true);
}

this.configManager.update(argv);

// disable the prompts that we don't want to prompt the user for
flags.disablePrompts([...requiredFlagsWithDisabledPrompt, ...optionalFlags]);

Expand Down
3 changes: 3 additions & 0 deletions src/commands/relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ export class RelayCommand extends BaseCommand {
// reset nodeAlias
self.configManager.setFlag(flags.nodeAliasesUnparsed, '');

self.configManager.update(argv);

flags.disablePrompts([flags.operatorId, flags.operatorKey]);

await self.configManager.executePrompt(task, RelayCommand.DEPLOY_FLAGS_LIST);
Expand Down Expand Up @@ -343,6 +345,7 @@ export class RelayCommand extends BaseCommand {
// reset nodeAlias
self.configManager.setFlag(flags.nodeAliasesUnparsed, '');

self.configManager.update(argv);
await self.configManager.executePrompt(task, RelayCommand.DESTROY_FLAGS_LIST);

// prompt if inputs are empty and set it in the context
Expand Down
20 changes: 11 additions & 9 deletions src/core/config/remote/common_flags_data_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ export class CommonFlagsDataWrapper implements ToObject<RemoteConfigCommonFlagsS
*/
public async handleFlags(argv: AnyObject): Promise<void> {
for (const flag of CommonFlagsDataWrapper.COMMON_FLAGS) {
await this.checkFlag(flag);
await this.checkFlag(flag, argv);
}
}

private async checkFlag(flag: CommandFlag): Promise<void> {
private async checkFlag(flag: CommandFlag, argv: AnyObject): Promise<void> {
const detectFlagMismatch = async () => {
const oldValue = this.flags[flag.constName] as string;
const newValue = this.configManager.getFlag<string>(flag);
Expand All @@ -61,7 +61,7 @@ export class CommonFlagsDataWrapper implements ToObject<RemoteConfigCommonFlagsS
// if its present but there is a mismatch warn user
else if (oldValue && oldValue !== newValue) {
const answer = await select<string>({
message: 'Value in remote config differs with the one you are passing, choose with which you want to keep',
message: 'Value in remote config differs with the one you are passing, choose which you want to use',
choices: [
{
name: `[old value] ${oldValue}`,
Expand All @@ -74,8 +74,13 @@ export class CommonFlagsDataWrapper implements ToObject<RemoteConfigCommonFlagsS
],
});

// Override if user chooses new the new value, else do nothing and keep the old one
if (answer === newValue) this.flags[flag.constName] = newValue;
// Override if user chooses new the new value, else override and keep the old one
if (answer === newValue) {
this.flags[flag.constName] = newValue;
} else {
this.configManager.setFlag(flag, oldValue);
argv[flag.constName] = oldValue;
}
}
};

Expand All @@ -86,14 +91,11 @@ export class CommonFlagsDataWrapper implements ToObject<RemoteConfigCommonFlagsS

// if the value is not set and exists, override it
else if (this.flags[flag.constName]) {
argv[flag.constName] = this.flags[flag.constName];
this.configManager.setFlag(flag, this.flags[flag.constName]);
}
}

private overrideFlagValue (flag: CommandFlag, argv: AnyObject): void {
this.configManager
}

public static async initializeEmpty(configManager: ConfigManager, argv: AnyObject): Promise<CommonFlagsDataWrapper> {
const commonFlagsDataWrapper = new CommonFlagsDataWrapper(configManager, {});
await commonFlagsDataWrapper.handleFlags(argv);
Expand Down

0 comments on commit 1e270e1

Please sign in to comment.