Skip to content

Commit 5230782

Browse files
committed
refactor(cli-repl): apply changes from review
Use async getConfig, add return types, remove unnecessary eslint comments, move bus variables into class state, use explicit private and public fields.
1 parent 5147039 commit 5230782

File tree

2 files changed

+82
-75
lines changed

2 files changed

+82
-75
lines changed

packages/cli-repl/src/cli-repl.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,9 @@ export class CliRepl implements MongoshIOProvider {
257257
}
258258

259259
/** Setup log writer and start logging. */
260-
private async startLogging(loggingAndTelemetry: MongoshLoggingAndTelemetry) {
260+
private async startLogging(
261+
loggingAndTelemetry: MongoshLoggingAndTelemetry
262+
): Promise<void> {
261263
await this.logManager.cleanupOldLogFiles();
262264
markTime(TimingCategories.Logging, 'cleaned up log files');
263265
const logger = await this.logManager.createLogWriter();
@@ -373,7 +375,7 @@ export class CliRepl implements MongoshIOProvider {
373375
this.globalConfig = await this.loadGlobalConfigFile();
374376
markTime(TimingCategories.UserConfigLoading, 'read global config files');
375377

376-
const disableLogging = this.getConfig('disableLogging');
378+
const disableLogging = await this.getConfig('disableLogging');
377379
if (disableLogging !== true) {
378380
await this.startLogging(loggingAndTelemetry);
379381
}
@@ -498,7 +500,7 @@ export class CliRepl implements MongoshIOProvider {
498500
if (!this.cliOptions.shell) {
499501
// We flush the telemetry data as part of exiting. Make sure we have
500502
// the right config value.
501-
this.setTelemetryEnabled(this.getConfig('enableTelemetry'));
503+
this.setTelemetryEnabled(await this.getConfig('enableTelemetry'));
502504
await this.exit(0);
503505
return;
504506
}
@@ -531,7 +533,7 @@ export class CliRepl implements MongoshIOProvider {
531533

532534
// We only enable/disable here, since the rc file/command line scripts
533535
// can disable the telemetry setting.
534-
this.setTelemetryEnabled(this.getConfig('enableTelemetry'));
536+
this.setTelemetryEnabled(await this.getConfig('enableTelemetry'));
535537
this.bus.emit('mongosh:start-mongosh-repl', { version });
536538
markTime(TimingCategories.REPLInstantiation, 'starting repl');
537539
await this.mongoshRepl.startRepl(initialized);
@@ -872,7 +874,9 @@ export class CliRepl implements MongoshIOProvider {
872874
* Implements getConfig from the {@link ConfigProvider} interface.
873875
*/
874876
// eslint-disable-next-line @typescript-eslint/require-await
875-
getConfig<K extends keyof CliUserConfig>(key: K): CliUserConfig[K] {
877+
async getConfig<K extends keyof CliUserConfig>(
878+
key: K
879+
): Promise<CliUserConfig[K]> {
876880
return (
877881
(this.config as CliUserConfig)[key] ??
878882
(this.globalConfig as CliUserConfig)?.[key] ??
@@ -1273,7 +1277,7 @@ export class CliRepl implements MongoshIOProvider {
12731277
}
12741278

12751279
try {
1276-
const updateURL = this.getConfig('updateURL').trim();
1280+
const updateURL = (await this.getConfig('updateURL')).trim();
12771281
if (!updateURL) return;
12781282

12791283
const localFilePath = this.shellHomeDirectory.localPath(

0 commit comments

Comments
 (0)