Skip to content

Commit 8b09254

Browse files
committed
avoid missing base command flags
1 parent 9e176de commit 8b09254

4 files changed

Lines changed: 42 additions & 37 deletions

File tree

packages/b2c-tooling-sdk/src/cli/base-command.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,43 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
194194
return input;
195195
}
196196

197-
protected loadConfiguration(): ResolvedB2CConfig {
198-
const options: LoadConfigOptions = {
197+
/**
198+
* Gets base configuration options from common flags.
199+
*
200+
* Subclasses should spread these options when overriding loadConfiguration()
201+
* to ensure common options like startDir are always included.
202+
*
203+
* @example
204+
* ```typescript
205+
* protected override loadConfiguration(): ResolvedB2CConfig {
206+
* const options: LoadConfigOptions = {
207+
* ...this.getBaseConfigOptions(),
208+
* // Add subclass-specific options here
209+
* };
210+
* return loadConfig(extractMyFlags(this.flags), options, this.getPluginSources());
211+
* }
212+
* ```
213+
*/
214+
protected getBaseConfigOptions(): LoadConfigOptions {
215+
return {
199216
instance: this.flags.instance,
200217
configPath: this.flags.config,
201218
startDir: this.flags['working-directory'],
202219
};
220+
}
203221

204-
const pluginSources: PluginSources = {
222+
/**
223+
* Gets plugin sources for configuration resolution.
224+
*/
225+
protected getPluginSources(): PluginSources {
226+
return {
205227
before: this.pluginSourcesBefore,
206228
after: this.pluginSourcesAfter,
207229
};
230+
}
208231

209-
return loadConfig({}, options, pluginSources);
232+
protected loadConfiguration(): ResolvedB2CConfig {
233+
return loadConfig({}, this.getBaseConfigOptions(), this.getPluginSources());
210234
}
211235

212236
/**

packages/b2c-tooling-sdk/src/cli/instance-command.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import {Command, Flags} from '@oclif/core';
77
import {OAuthCommand} from './oauth-command.js';
88
import {loadConfig, extractInstanceFlags} from './config.js';
9-
import type {LoadConfigOptions, PluginSources} from './config.js';
109
import type {ResolvedB2CConfig} from '../config/index.js';
1110
import type {B2CInstance} from '../instance/index.js';
1211
import {t} from '../i18n/index.js';
@@ -160,17 +159,11 @@ export abstract class InstanceCommand<T extends typeof Command> extends OAuthCom
160159
}
161160

162161
protected override loadConfiguration(): ResolvedB2CConfig {
163-
const options: LoadConfigOptions = {
164-
instance: this.flags.instance,
165-
configPath: this.flags.config,
166-
};
167-
168-
const pluginSources: PluginSources = {
169-
before: this.pluginSourcesBefore,
170-
after: this.pluginSourcesAfter,
171-
};
172-
173-
return loadConfig(extractInstanceFlags(this.flags as Record<string, unknown>), options, pluginSources);
162+
return loadConfig(
163+
extractInstanceFlags(this.flags as Record<string, unknown>),
164+
this.getBaseConfigOptions(),
165+
this.getPluginSources(),
166+
);
174167
}
175168

176169
/**

packages/b2c-tooling-sdk/src/cli/mrt-command.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import {Command, Flags} from '@oclif/core';
77
import {BaseCommand} from './base-command.js';
88
import {loadConfig, extractMrtFlags} from './config.js';
9-
import type {LoadConfigOptions, PluginSources} from './config.js';
9+
import type {LoadConfigOptions} from './config.js';
1010
import type {ResolvedB2CConfig} from '../config/index.js';
1111
import type {AuthStrategy} from '../auth/types.js';
1212
import {MrtClient} from '../platform/mrt.js';
@@ -63,18 +63,12 @@ export abstract class MrtCommand<T extends typeof Command> extends BaseCommand<T
6363

6464
protected override loadConfiguration(): ResolvedB2CConfig {
6565
const options: LoadConfigOptions = {
66-
instance: this.flags.instance,
67-
configPath: this.flags.config,
66+
...this.getBaseConfigOptions(),
6867
cloudOrigin: this.flags['cloud-origin'] as string | undefined, // MobifySource uses this to load ~/.mobify--[hostname] if set
6968
credentialsFile: this.flags['credentials-file'] as string | undefined, // Override path to MRT credentials file
7069
};
7170

72-
const pluginSources: PluginSources = {
73-
before: this.pluginSourcesBefore,
74-
after: this.pluginSourcesAfter,
75-
};
76-
77-
return loadConfig(extractMrtFlags(this.flags as Record<string, unknown>), options, pluginSources);
71+
return loadConfig(extractMrtFlags(this.flags as Record<string, unknown>), options, this.getPluginSources());
7872
}
7973

8074
/**

packages/b2c-tooling-sdk/src/cli/oauth-command.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import {Command, Flags} from '@oclif/core';
77
import {BaseCommand} from './base-command.js';
88
import {loadConfig, extractOAuthFlags, ALL_AUTH_METHODS} from './config.js';
9-
import type {LoadConfigOptions, AuthMethod, PluginSources} from './config.js';
9+
import type {AuthMethod} from './config.js';
1010
import type {ResolvedB2CConfig} from '../config/index.js';
1111
import {OAuthStrategy} from '../auth/oauth.js';
1212
import {ImplicitOAuthStrategy} from '../auth/oauth-implicit.js';
@@ -84,17 +84,11 @@ export abstract class OAuthCommand<T extends typeof Command> extends BaseCommand
8484
}
8585

8686
protected override loadConfiguration(): ResolvedB2CConfig {
87-
const options: LoadConfigOptions = {
88-
instance: this.flags.instance,
89-
configPath: this.flags.config,
90-
};
91-
92-
const pluginSources: PluginSources = {
93-
before: this.pluginSourcesBefore,
94-
after: this.pluginSourcesAfter,
95-
};
96-
97-
return loadConfig(extractOAuthFlags(this.flags as Record<string, unknown>), options, pluginSources);
87+
return loadConfig(
88+
extractOAuthFlags(this.flags as Record<string, unknown>),
89+
this.getBaseConfigOptions(),
90+
this.getPluginSources(),
91+
);
9892
}
9993

10094
/**

0 commit comments

Comments
 (0)