Skip to content

Commit

Permalink
chore: remove remaining circular dependencies (#944)
Browse files Browse the repository at this point in the history
Signed-off-by: Jeromy Cannon <[email protected]>
  • Loading branch information
jeromy-cannon authored Dec 9, 2024
1 parent de9ec2e commit f546a79
Show file tree
Hide file tree
Showing 25 changed files with 528 additions and 538 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"test-e2e-relay": "cross-env MOCHA_SUITE_NAME=\"Mocha E2E Relay Tests\" c8 --report-dir='coverage/e2e-relay' mocha 'test/e2e/commands/relay.test.ts' --reporter-options configFile=mocha-multi-reporter.json,cmrOutput=mocha-junit-reporter+mochaFile+junit-e2e-relay.xml",
"solo-test": "tsx --no-deprecation --no-warnings solo.ts",
"solo": "node --no-deprecation --no-warnings dist/solo.js",
"check": "remark . --quiet --frail && eslint . && tsc && (madge --circular src/* || true) && cd docs; jsdoc -c jsdoc.conf.json",
"format": "remark . --quiet --frail --output && eslint --fix . && tsc && madge --circular src/* || true",
"check": "remark . --quiet --frail && eslint . && tsc && madge --circular src/* && cd docs; jsdoc -c jsdoc.conf.json",
"format": "remark . --quiet --frail --output && eslint --fix . && tsc && madge --circular src/*",
"test-setup": "./test/e2e/setup-e2e.sh",
"build": "rm -Rf dist && tsc && node resources/post-build-script.js"
},
Expand Down
8 changes: 4 additions & 4 deletions src/commands/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class AccountCommand extends BaseCommand {
title: 'Initialize',
task: async (ctx, task) => {
self.configManager.update(argv);
await flags.executePrompt(task, self.configManager, [flags.namespace]);
await self.configManager.executePrompt(task, [flags.namespace]);

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

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

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

const config = {
accountId: self.configManager.getFlag<string>(flags.accountId) as string,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {type ConfigManager} from '../core/config_manager.js';
import {type DependencyManager} from '../core/dependency_managers/index.js';
import {type Opts} from '../types/command_types.js';
import {type CommandFlag} from '../types/flag_types.js';
import {type Lease} from '../core/lease/types.js';
import {type Lease} from '../core/lease/lease.js';
import {Listr} from 'listr2';

export interface CommandHandlers {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class ClusterCommand extends BaseCommand {
title: 'Initialize',
task: async (ctx, task) => {
self.configManager.update(argv);
await flags.executePrompt(task, self.configManager, [
await self.configManager.executePrompt(task, [
flags.chartDirectory,
flags.clusterSetupNamespace,
flags.deployCertManager,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class DeploymentCommand extends BaseCommand {
self.configManager.update(argv);
self.logger.debug('Loaded cached config', {config: self.configManager.config});

await flags.executePrompt(task, self.configManager, DeploymentCommand.DEPLOY_FLAGS_LIST);
await self.configManager.executePrompt(task, DeploymentCommand.DEPLOY_FLAGS_LIST);

ctx.config = {
contextClusterUnparsed: self.configManager.getFlag<string>(flags.contextClusterUnparsed),
Expand Down
28 changes: 0 additions & 28 deletions src/commands/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*
*/
import * as constants from '../core/constants.js';
import {ConfigManager} from '../core/config_manager.js';
import * as version from '../../version.js';
import path from 'path';
import {type CommandFlag} from '../types/flag_types.js';
Expand Down Expand Up @@ -86,33 +85,6 @@ export class Flags {
return await Flags.prompt('toggle', task, input, defaultValue, promptMessage, emptyCheckMessage, flagName);
}

/**
* Run prompts for the given set of flags
* @param task task object from listr2
* @param configManager config manager to store flag values
* @param flagList list of flag objects
*/
static async executePrompt(
task: ListrTaskWrapper<any, any, any>,
configManager: ConfigManager,
flagList: CommandFlag[] = [],
) {
if (!configManager || !(configManager instanceof ConfigManager)) {
throw new IllegalArgumentError('an instance of ConfigManager is required');
}
for (const flag of flagList) {
if (flag.definition.disablePrompt || flag.prompt === undefined) {
continue;
}

if (configManager.getFlag(Flags.quiet)) {
return;
}
const input = await flag.prompt(task, configManager.getFlag(flag));
configManager.setFlag(flag, input);
}
}

/**
* Disable prompts for the given set of flags
* @param flags list of flags to disable prompts for
Expand Down
4 changes: 2 additions & 2 deletions src/commands/mirror_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class MirrorNodeCommand extends BaseCommand {
flags.pinger,
]);

await flags.executePrompt(task, self.configManager, MirrorNodeCommand.DEPLOY_FLAGS_LIST);
await self.configManager.executePrompt(task, MirrorNodeCommand.DEPLOY_FLAGS_LIST);

ctx.config = this.getConfig(MirrorNodeCommand.DEPLOY_CONFIGS_NAME, MirrorNodeCommand.DEPLOY_FLAGS_LIST, [
'chartPath',
Expand Down Expand Up @@ -473,7 +473,7 @@ export class MirrorNodeCommand extends BaseCommand {
}

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

// @ts-ignore
ctx.config = {
Expand Down
8 changes: 2 additions & 6 deletions src/commands/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export class NetworkCommand extends BaseCommand {
flags.envoyIps,
]);

await flags.executePrompt(task, this.configManager, NetworkCommand.DEPLOY_FLAGS_LIST);
await this.configManager.executePrompt(task, NetworkCommand.DEPLOY_FLAGS_LIST);

// create a config object for subsequent steps
const config = this.getConfig(NetworkCommand.DEPLOY_CONFIGS_NAME, NetworkCommand.DEPLOY_FLAGS_LIST, [
Expand Down Expand Up @@ -567,11 +567,7 @@ export class NetworkCommand extends BaseCommand {
}

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

ctx.config = {
deletePvcs: self.configManager.getFlag<boolean>(flags.deletePvcs) as boolean,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/node/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {ComponentType, ConsensusNodeStates} from '../../core/config/remote/enume
import {RemoteConfigTasks} from '../../core/config/remote/remote_config_tasks.js';
import type {SoloLogger} from '../../core/logging.js';
import type {NodeCommandTasks} from './tasks.js';
import {type Lease} from '../../core/lease/types.js';
import {type Lease} from '../../core/lease/lease.js';
import {NodeSubcommandType} from '../../core/enumerations.js';
import {type BaseCommand, type CommandHandlers} from '../base.js';
import {NodeHelper} from './helper.js';
Expand Down
4 changes: 2 additions & 2 deletions src/commands/node/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ import type {
NodeRefreshConfigClass,
NodeUpdateConfigClass,
} from './configs.js';
import {type Lease} from '../../core/lease/types.js';
import {type Lease} from '../../core/lease/lease.js';
import {ListrLease} from '../../core/lease/listr_lease.js';
import {Duration} from '../../core/time/duration.js';
import {type BaseCommand} from '../base.js';
Expand Down Expand Up @@ -1645,7 +1645,7 @@ export class NodeCommandTasks {
}
}

await flags.executePrompt(task, this.configManager, flagsToPrompt);
await this.configManager.executePrompt(task, flagsToPrompt);

const config = await configInit(argv, ctx, task);
ctx.config = config;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export class RelayCommand extends BaseCommand {

self.configManager.update(argv);

await flags.executePrompt(task, self.configManager, RelayCommand.DEPLOY_FLAGS_LIST);
await self.configManager.executePrompt(task, RelayCommand.DEPLOY_FLAGS_LIST);

// prompt if inputs are empty and set it in the context
ctx.config = this.getConfig(RelayCommand.DEPLOY_CONFIGS_NAME, RelayCommand.DEPLOY_FLAGS_LIST, [
Expand Down Expand Up @@ -328,7 +328,7 @@ export class RelayCommand extends BaseCommand {
self.configManager.setFlag(flags.nodeAliasesUnparsed, '');

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

// prompt if inputs are empty and set it in the context
ctx.config = {
Expand Down
24 changes: 22 additions & 2 deletions src/core/config_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
* limitations under the License.
*
*/
import {SoloError, MissingArgumentError} from './errors.js';
import {SoloError, MissingArgumentError, IllegalArgumentError} from './errors.js';
import {SoloLogger} from './logging.js';
import {Flags as flags} from '../commands/flags.js';
import {Flags, Flags as flags} from '../commands/flags.js';
import * as paths from 'path';
import * as helpers from './helpers.js';
import type * as yargs from 'yargs';
import {type CommandFlag} from '../types/flag_types.js';
import {type ListrTaskWrapper} from 'listr2';

/**
* ConfigManager cache command flag values so that user doesn't need to enter the same values repeatedly.
Expand Down Expand Up @@ -158,4 +159,23 @@ export class ConfigManager {
getVersion(): string {
return this.config.version;
}

/**
* Run prompts for the given set of flags
* @param task task object from listr2
* @param flagList list of flag objects
*/
async executePrompt(task: ListrTaskWrapper<any, any, any>, flagList: CommandFlag[] = []) {
for (const flag of flagList) {
if (flag.definition.disablePrompt || flag.prompt === undefined) {
continue;
}

if (this.getFlag(Flags.quiet)) {
return;
}
const input = await flag.prompt(task, this.getFlag(flag));
this.setFlag(flag, input);
}
}
}
Loading

0 comments on commit f546a79

Please sign in to comment.