@@ -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
0 commit comments