Skip to content

Commit 7a7c872

Browse files
authored
feat: add skipStartupWarnings flag to skip warnings on demand MONGOSH-2371 (#2501)
1 parent edffa90 commit 7a7c872

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ variable. For detailed instructions for each of our supported platforms, please
4444
--eval [arg] Evaluate javascript
4545
--json[=canonical|relaxed] Print result of --eval as Extended JSON, including errors
4646
--retryWrites[=true|false] Automatically retry write operations upon transient network errors (Default: true)
47+
--skipStartupWarnings Do not display server startup warnings
4748
4849
Authentication Options:
4950

packages/arg-parser/src/cli-options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export interface CliOptions {
3838
quiet?: boolean;
3939
retryWrites?: boolean;
4040
shell?: boolean;
41+
skipStartupWarnings?: boolean;
4142
tls?: boolean;
4243
tlsAllowInvalidCertificates?: boolean;
4344
tlsAllowInvalidHostnames?: boolean;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const OPTIONS = {
7171
'retryWrites',
7272
'shell',
7373
'smokeTests',
74+
'skipStartupWarnings',
7475
'ssl',
7576
'sslAllowInvalidCertificates',
7677
'sslAllowInvalidHostnames',

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,25 @@ describe('MongoshNodeRepl', function () {
13451345
'The server generated these startup warnings when booting'
13461346
);
13471347
});
1348+
1349+
it('startup warnings are absent when skipStartupWarnings flag is present', async function () {
1350+
mongoshRepl.shellCliOptions.skipStartupWarnings = true;
1351+
// Make sure the startupWarnings resolves with errors
1352+
sp.runCommandWithCheck
1353+
.withArgs(
1354+
ADMIN_DB,
1355+
{
1356+
getLog: 'startupWarnings',
1357+
},
1358+
{}
1359+
)
1360+
.resolves({ ok: 1, log: logLines });
1361+
1362+
await mongoshRepl.initialize(serviceProvider);
1363+
expect(output).to.not.contain(
1364+
'The server generated these startup warnings when booting'
1365+
);
1366+
});
13481367
});
13491368
}
13501369
});

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ declare const __non_webpack_require__: any;
5757
*/
5858
export type MongoshCliOptions = ShellCliOptions & {
5959
quiet?: boolean;
60+
skipStartupWarnings?: boolean;
6061
/**
6162
* Whether to instantiate a Node.js REPL instance, including support
6263
* for async error tracking, or not.
@@ -375,10 +376,12 @@ class MongoshNodeRepl implements EvaluationListener {
375376
const { shellApi } = instanceState;
376377
// Assuming `instanceState.fetchConnectionInfo()` was already called above
377378
const connectionInfo = instanceState.cachedConnectionInfo();
378-
// Skipping startup warnings (see https://jira.mongodb.org/browse/MONGOSH-1776)
379-
const bannerCommands = connectionInfo?.extraInfo?.is_local_atlas
380-
? ['automationNotices', 'nonGenuineMongoDBCheck']
381-
: ['startupWarnings', 'automationNotices', 'nonGenuineMongoDBCheck'];
379+
// Skipping startup warnings (see https://jira.mongodb.org/browse/MONGOSH-1776 and https://jira.mongodb.org/browse/MONGOSH-2371)
380+
const bannerCommands =
381+
connectionInfo?.extraInfo?.is_local_atlas ||
382+
this.shellCliOptions.skipStartupWarnings
383+
? ['automationNotices', 'nonGenuineMongoDBCheck']
384+
: ['startupWarnings', 'automationNotices', 'nonGenuineMongoDBCheck'];
382385
const banners = await Promise.all(
383386
bannerCommands.map(
384387
async (command) => await shellApi._untrackedShow(command)

0 commit comments

Comments
 (0)