Skip to content

Commit

Permalink
fix: use default values for flags during init (#753)
Browse files Browse the repository at this point in the history
Signed-off-by: Lenin Mehedy <lenin.mehedy@swirldslabs.com>
  • Loading branch information
leninmehedy authored Feb 14, 2024
1 parent 520cb47 commit 167fb3c
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 18 deletions.
4 changes: 2 additions & 2 deletions solo/src/commands/cluster.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class ClusterCommand extends BaseCommand {
{
title: 'Initialize',
task: async (ctx, task) => {
self.configManager.load(argv)
self.configManager.update(argv)
await prompts.execute(task, self.configManager, [
flags.clusterSetupNamespace,
flags.chartDirectory,
Expand Down Expand Up @@ -175,7 +175,7 @@ export class ClusterCommand extends BaseCommand {
process.exit(0)
}

self.configManager.load(argv)
self.configManager.update(argv)
const clusterName = self.configManager.getFlag(flags.clusterName)
const clusterSetupNamespace = self.configManager.getFlag(flags.clusterSetupNamespace)
ctx.config = {
Expand Down
10 changes: 9 additions & 1 deletion solo/src/commands/init.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,15 @@ export class InitCommand extends BaseCommand {
command: 'init',
desc: 'Initialize local environment and default flags',
builder: y => {
flags.setCommandFlags(y, ...flags.allFlags)
flags.setCommandFlags(y,
flags.releaseTag,
flags.nodeIDs,
flags.namespace,
flags.clusterSetupNamespace,
flags.cacheDir,
flags.chartDirectory,
flags.keyFormat,
)
},
handler: (argv) => {
initCmd.init(argv).then(r => {
Expand Down
4 changes: 2 additions & 2 deletions solo/src/commands/network.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class NetworkCommand extends BaseCommand {
flags.enablePrometheusSvcMonitor
]

this.configManager.load(argv)
this.configManager.update(argv)
this.logger.debug('Loaded cached config', { config: this.configManager.config })
await prompts.execute(task, this.configManager, flagList)

Expand Down Expand Up @@ -243,7 +243,7 @@ export class NetworkCommand extends BaseCommand {
}
}

self.configManager.load(argv)
self.configManager.update(argv)
await prompts.execute(task, self.configManager, [
flags.namespace,
flags.deletePvcs
Expand Down
8 changes: 4 additions & 4 deletions solo/src/commands/node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class NodeCommand extends BaseCommand {
{
title: 'Initialize',
task: async (ctx, task) => {
self.configManager.load(argv)
self.configManager.update(argv)
await prompts.execute(task, self.configManager, [
flags.namespace,
flags.nodeIDs,
Expand Down Expand Up @@ -416,7 +416,7 @@ export class NodeCommand extends BaseCommand {
{
title: 'Initialize',
task: async (ctx, task) => {
self.configManager.load(argv)
self.configManager.update(argv)
await prompts.execute(task, self.configManager, [
flags.namespace,
flags.nodeIDs,
Expand Down Expand Up @@ -515,7 +515,7 @@ export class NodeCommand extends BaseCommand {
{
title: 'Initialize',
task: async (ctx, task) => {
self.configManager.load(argv)
self.configManager.update(argv)
await prompts.execute(task, self.configManager, [
flags.namespace,
flags.nodeIDs
Expand Down Expand Up @@ -577,7 +577,7 @@ export class NodeCommand extends BaseCommand {
{
title: 'Initialize',
task: async (ctx, task) => {
self.configManager.load(argv)
self.configManager.update(argv)
await prompts.execute(task, self.configManager, [
flags.nodeIDs,
flags.cacheDir,
Expand Down
4 changes: 2 additions & 2 deletions solo/src/commands/relay.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class RelayCommand extends BaseCommand {
{
title: 'Initialize',
task: async (ctx, task) => {
self.configManager.load(argv)
self.configManager.update(argv)

// extract config values
const valuesFile = self.configManager.getFlag(flags.valuesFile)
Expand Down Expand Up @@ -176,7 +176,7 @@ export class RelayCommand extends BaseCommand {
{
title: 'Initialize',
task: async (ctx, task) => {
self.configManager.load(argv)
self.configManager.update(argv)

// extract config values
const nodeIds = self.configManager.getFlag(flags.nodeIDs)
Expand Down
2 changes: 1 addition & 1 deletion solo/src/core/config_manager.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class ConfigManager {
// argv takes precedence, nothing to do
} else if (this.hasFlag(flag)) {
argv[key] = this.getFlag(flag)
} else if (argv._[0] !== 'init') {
} else {
argv[key] = flag.definition.defaultValue
}
}
Expand Down
5 changes: 2 additions & 3 deletions solo/test/e2e/commands/node.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ describe.each([
argv[flags.cacheDir.name] = cacheDir
argv[flags.force.name] = false
argv[flags.chainId.name] = constants.HEDERA_CHAIN_ID
argv[flags.chainId.name] = constants.HEDERA_CHAIN_ID
argv[flags.generateGossipKeys.name] = false
argv[flags.generateTlsKeys.name] = true
argv[flags.applicationProperties.name] = flags.applicationProperties.definition.defaultValue
Expand All @@ -108,8 +107,7 @@ describe.each([
argv[flags.clusterName.name] = 'kind-solo-e2e'
argv[flags.clusterSetupNamespace.name] = 'solo-e2e-cluster'
argv[flags.updateAccountKeys.name] = true
configManager.update(argv, true)

configManager.update(argv)
const nodeIds = argv[flags.nodeIDs.name].split(',')

afterEach(() => {
Expand All @@ -122,6 +120,7 @@ describe.each([
await shellRunner.run(`test/scripts/gen-legacy-keys.sh ${nodeIds.join(',')} ${path.join(cacheDir, 'keys')}`)
}
}, 60000)

it('node setup should succeed', async () => {
expect.assertions(1)
try {
Expand Down
6 changes: 3 additions & 3 deletions solo/test/unit/core/config_manager.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe('ConfigManager', () => {
expect(cm.getFlag(flags.devMode)).toBeFalsy()

const argv = {}
argv[flags.devMode.name] = true // force flag is set in argv
argv[flags.devMode.name] = true // devMode flag is set in argv but cached config has it

const argv2 = cm.applyPrecedence(argv, aliases)
expect(cm.getFlag(flags.devMode)).toBeFalsy() // shouldn't have changed the config yet
Expand All @@ -141,7 +141,7 @@ describe('ConfigManager', () => {
cm.setFlag(flags.devMode, false)
expect(cm.getFlag(flags.devMode)).toBeFalsy()

const argv = {} // force flag is not set in argv
const argv = {} // devMode flag is not set in argv
const argv2 = cm.applyPrecedence(argv, aliases)
expect(cm.getFlag(flags.devMode)).toBeFalsy() // shouldn't have changed
expect(argv2[flags.devMode.name]).toStrictEqual(cm.getFlag(flags.devMode)) // should inherit from config
Expand All @@ -153,7 +153,7 @@ describe('ConfigManager', () => {
const cm = new ConfigManager(testLogger, tmpFile)
expect(cm.hasFlag(flags.devMode)).toBeFalsy() // shouldn't have set

const argv = { _: ['node', 'setup'] }// force flag is not set in argv and command is not init
const argv = {} // devMode flag is not set in argv and cached config doesn't have it either
const argv2 = cm.applyPrecedence(argv, aliases)
expect(cm.hasFlag(flags.devMode)).toBeFalsy() // shouldn't have set
expect(argv2[flags.devMode.name]).toBeFalsy() // should have set from the default
Expand Down

0 comments on commit 167fb3c

Please sign in to comment.