Skip to content

Commit ff9e123

Browse files
chore: address copilot suggestions
1 parent 98cc28f commit ff9e123

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

src/common/config/configUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ export function isConnectionSpecifier(arg: string | undefined): boolean {
4242
arg !== undefined &&
4343
(arg.startsWith("mongodb://") ||
4444
arg.startsWith("mongodb+srv://") ||
45-
// Strings starting with a hyphen `-` are generally a sign of CLI
46-
// flag so we exclude them from the possibility of being a
45+
// Strings starting with double hyphens `--` are generally a sign of
46+
// CLI flag so we exclude them from the possibility of being a
4747
// connection specifier.
48-
!(arg.endsWith(".js") || arg.endsWith(".mongodb") || arg.startsWith("-")))
48+
!(arg.endsWith(".js") || arg.endsWith(".mongodb") || arg.startsWith("--")))
4949
);
5050
}
5151

src/common/config/createUserConfig.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,23 @@ function parseUserConfigSources(cliArguments: string[]): {
108108
// no-op statement so ESLint does not complain.
109109
void endOfFlagArguments;
110110

111+
// A connectionSpecifier can be one of:
112+
// - database name
113+
// - host name
114+
// - ip address
115+
// - replica set specifier
116+
// - complete connection string
117+
let connectionSpecifier: string | undefined = undefined;
111118
const [maybeConnectionSpecifier, ...unknownArguments] = positionalAndUnknownArguments;
112-
// If the extracted connection specifier is not a connection specifier
113-
// indeed, then we push it back to the unknown arguments list. This might
114-
// happen for example when an unknown argument is provided without ever
115-
// specifying a positional argument.
116-
if (typeof maybeConnectionSpecifier !== "string" || !isConnectionSpecifier(maybeConnectionSpecifier)) {
117-
if (maybeConnectionSpecifier) {
118-
unknownArguments.unshift(maybeConnectionSpecifier);
119-
}
119+
120+
if (typeof maybeConnectionSpecifier === "string" && isConnectionSpecifier(maybeConnectionSpecifier)) {
121+
connectionSpecifier = maybeConnectionSpecifier;
122+
} else if (maybeConnectionSpecifier !== undefined) {
123+
// If the extracted connection specifier is not a connection specifier
124+
// indeed, then we push it back to the unknown arguments list. This might
125+
// happen for example when an unknown argument is provided without ever
126+
// specifying a positional argument.
127+
unknownArguments.unshift(maybeConnectionSpecifier);
120128
}
121129

122130
return {
@@ -142,16 +150,7 @@ function parseUserConfigSources(cliArguments: string[]): {
142150
})
143151
.filter((argument) => typeof argument === "string"),
144152
userAndArgsParserConfig: parsedUserAndArgsParserConfig,
145-
// A connectionSpecifier can be one of:
146-
// - database name
147-
// - host name
148-
// - ip address
149-
// - replica set specifier
150-
// - complete connection string
151-
connectionSpecifier:
152-
typeof maybeConnectionSpecifier === "string" && isConnectionSpecifier(maybeConnectionSpecifier)
153-
? String(maybeConnectionSpecifier)
154-
: undefined,
153+
connectionSpecifier,
155154
};
156155
}
157156

tests/unit/common/config.test.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -916,16 +916,17 @@ describe("keychain management", () => {
916916
const testCases = [
917917
{ cliArg: "apiClientId", secretKind: "user" },
918918
{ cliArg: "apiClientSecret", secretKind: "password" },
919-
// Note: These arguments were part of original test cases before
920-
// refactor of Config but because now we use yargs-parser to strictly
921-
// parse the config and do not allow unknown arguments to creep into the
922-
// final results, these arguments never end up in the config. It is
923-
// because we have the mongosh OPTIONS copied over from the repo and the
924-
// copied object does not contain these are parse targets.
925-
926-
// TODO: Whenever we finish importing OPTIONS from mongosh these test
927-
// cases should be good to be enabled again.
928-
919+
/*
920+
* Note: These arguments were part of original test cases before
921+
* refactor of Config but because now we use yargs-parser to strictly
922+
* parse the config and do not allow unknown arguments to creep into the
923+
* final results, these arguments never end up in the config. It is
924+
* because we have the mongosh OPTIONS copied over from the repo and the
925+
* copied object does not contain these as parse targets.
926+
*
927+
* TODO: Whenever we finish importing OPTIONS from mongosh these test
928+
* cases should be good to be enabled again.
929+
*/
929930
// { cliArg: "awsAccessKeyId", secretKind: "password" },
930931
// { cliArg: "awsIamSessionToken", secretKind: "password" },
931932
// { cliArg: "awsSecretAccessKey", secretKind: "password" },

0 commit comments

Comments
 (0)