Skip to content

Commit 5347c87

Browse files
authored
chore: ensure that usage text in README files is up-to-date MONGOSH-741 (#1982)
* chore: ensure that usage text in README files is up-to-date MONGOSH-741 * fixup: first run of `npm run update-cli-usage-text packages/*/*.md *.md`
1 parent 992283a commit 5347c87

File tree

6 files changed

+123
-1
lines changed

6 files changed

+123
-1
lines changed

.github/workflows/cron-tasks.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ jobs:
6666
git add .evergreen.yml
6767
git commit --no-allow-empty -m "chore: update evergreen config" || true
6868
69+
- name: Regenerate CLI usage text in README files
70+
run: |
71+
npm run update-cli-usage-text packages/*/*.md *.md
72+
git add packages/*/*.md *.md
73+
git commit --no-allow-empty -m "chore: update CLI usage text" || true
74+
6975
- name: Create pull request
7076
id: cpr
7177
uses: peter-evans/create-pull-request@v6

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ variable. For detailed instructions for each of our supported platforms, please
2323
[installation documentation](https://docs.mongodb.com/mongodb-shell/install#mdb-shell-install).
2424

2525
## CLI Usage
26+
27+
<!-- AUTOMATICALLY_INSERT_CLI_USAGE -->
28+
2629
```shell
2730
$ mongosh [options] [db address] [file names (ending in .js or .mongodb)]
2831

@@ -49,6 +52,9 @@ variable. For detailed instructions for each of our supported platforms, please
4952
--authenticationDatabase [arg] User source (defaults to dbname)
5053
--authenticationMechanism [arg] Authentication mechanism
5154
--awsIamSessionToken [arg] AWS IAM Temporary Session Token ID
55+
--gssapiServiceName [arg] Service name to use when authenticating using GSSAPI/Kerberos
56+
--sspiHostnameCanonicalization [arg] Specify the SSPI hostname canonicalization (none or forward, available on Windows)
57+
--sspiRealmOverride [arg] Specify the SSPI server realm (available on Windows)
5258
5359
TLS Options:
5460
@@ -97,6 +103,8 @@ variable. For detailed instructions for each of our supported platforms, please
97103
For more information on usage: https://docs.mongodb.com/mongodb-shell.
98104
```
99105

106+
<!-- /AUTOMATICALLY_INSERT_CLI_USAGE -->
107+
100108
## Local Development
101109

102110
### Requirements

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"update-third-party-notices": "mongodb-sbom-tools generate-3rd-party-notices --product='mongosh' --dependencies=.sbom/dependencies.json > THIRD_PARTY_NOTICES.md",
5353
"update-node-js-versions": "npx @pkgjs/nv ls v20 > .evergreen/node-20-latest.json && npx @pkgjs/nv ls v16 > .evergreen/node-16-latest.json",
5454
"update-evergreen-config": "npm run test-evergreen-expansions && node .evergreen/generate-evergreen-yml.js .evergreen/evergreen.yml.in > .evergreen.yml",
55+
"update-cli-usage-text": "node scripts/update-cli-usage-text.js",
5556
"mark-ci-required-optional-dependencies": "ts-node scripts/mark-ci-required-optional-dependencies.ts",
5657
"write-node-js-dep": "node scripts/write-nodejs-dep > .sbom/node-js-dep.json",
5758
"scan-node-js": "mongodb-sbom-tools scan-node-js --version=$NODE_JS_VERSION > .sbom/node-js-vuln.json",

packages/cli-repl/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ of mongosh, visit https://www.mongodb.com/try/download/shell.
99

1010
## Usage
1111

12+
<!-- AUTOMATICALLY_INSERT_CLI_USAGE -->
13+
1214
```shell
1315
$ mongosh [options] [db address] [file names (ending in .js or .mongodb)]
1416

@@ -35,6 +37,9 @@ of mongosh, visit https://www.mongodb.com/try/download/shell.
3537
--authenticationDatabase [arg] User source (defaults to dbname)
3638
--authenticationMechanism [arg] Authentication mechanism
3739
--awsIamSessionToken [arg] AWS IAM Temporary Session Token ID
40+
--gssapiServiceName [arg] Service name to use when authenticating using GSSAPI/Kerberos
41+
--sspiHostnameCanonicalization [arg] Specify the SSPI hostname canonicalization (none or forward, available on Windows)
42+
--sspiRealmOverride [arg] Specify the SSPI server realm (available on Windows)
3843
3944
TLS Options:
4045
@@ -45,6 +50,7 @@ of mongosh, visit https://www.mongodb.com/try/download/shell.
4550
--tlsAllowInvalidHostnames Allow connections to servers with non-matching hostnames
4651
--tlsAllowInvalidCertificates Allow connections to servers with invalid certificates
4752
--tlsCertificateSelector [arg] TLS Certificate in system store (Windows and macOS only)
53+
--tlsCRLFile [arg] Specifies the .pem file that contains the Certificate Revocation List
4854
--tlsDisabledProtocols [arg] Comma separated list of TLS protocols to disable [TLS1_0,TLS1_1,TLS1_2]
4955
--tlsUseSystemCA Load the operating system trusted certificate list
5056
--tlsFIPSMode Enable the system TLS library's FIPS mode
@@ -80,9 +86,10 @@ of mongosh, visit https://www.mongodb.com/try/download/shell.
8086
$ mongosh mongodb://192.168.0.5:9999/ships
8187

8288
For more information on usage: https://docs.mongodb.com/mongodb-shell.
83-
8489
```
8590

91+
<!-- /AUTOMATICALLY_INSERT_CLI_USAGE -->
92+
8693
### Log Format
8794

8895
CLI REPL listens to a few events via a message bus that are then logged to

packages/mongosh/README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,88 @@ npm i -g mongosh
88

99
This package is a convenience distribution of mongosh. To download a fully supported version
1010
of mongosh, visit https://www.mongodb.com/try/download/shell.
11+
12+
## Usage
13+
14+
## CLI Usage
15+
16+
<!-- AUTOMATICALLY_INSERT_CLI_USAGE -->
17+
18+
```shell
19+
$ mongosh [options] [db address] [file names (ending in .js or .mongodb)]
20+
21+
Options:
22+
23+
-h, --help Show this usage information
24+
-f, --file [arg] Load the specified mongosh script
25+
--host [arg] Server to connect to
26+
--port [arg] Port to connect to
27+
--build-info Show build information
28+
--version Show version information
29+
--quiet Silence output from the shell during the connection process
30+
--shell Run the shell after executing files
31+
--nodb Don't connect to mongod on startup - no 'db address' [arg] expected
32+
--norc Will not run the '.mongoshrc.js' file on start up
33+
--eval [arg] Evaluate javascript
34+
--json[=canonical|relaxed] Print result of --eval as Extended JSON, including errors
35+
--retryWrites[=true|false] Automatically retry write operations upon transient network errors (Default: true)
36+
37+
Authentication Options:
38+
39+
-u, --username [arg] Username for authentication
40+
-p, --password [arg] Password for authentication
41+
--authenticationDatabase [arg] User source (defaults to dbname)
42+
--authenticationMechanism [arg] Authentication mechanism
43+
--awsIamSessionToken [arg] AWS IAM Temporary Session Token ID
44+
--gssapiServiceName [arg] Service name to use when authenticating using GSSAPI/Kerberos
45+
--sspiHostnameCanonicalization [arg] Specify the SSPI hostname canonicalization (none or forward, available on Windows)
46+
--sspiRealmOverride [arg] Specify the SSPI server realm (available on Windows)
47+
48+
TLS Options:
49+
50+
--tls Use TLS for all connections
51+
--tlsCertificateKeyFile [arg] PEM certificate/key file for TLS
52+
--tlsCertificateKeyFilePassword [arg] Password for key in PEM file for TLS
53+
--tlsCAFile [arg] Certificate Authority file for TLS
54+
--tlsAllowInvalidHostnames Allow connections to servers with non-matching hostnames
55+
--tlsAllowInvalidCertificates Allow connections to servers with invalid certificates
56+
--tlsCertificateSelector [arg] TLS Certificate in system store (Windows and macOS only)
57+
--tlsCRLFile [arg] Specifies the .pem file that contains the Certificate Revocation List
58+
--tlsDisabledProtocols [arg] Comma separated list of TLS protocols to disable [TLS1_0,TLS1_1,TLS1_2]
59+
--tlsUseSystemCA Load the operating system trusted certificate list
60+
--tlsFIPSMode Enable the system TLS library's FIPS mode
61+
62+
API version options:
63+
64+
--apiVersion [arg] Specifies the API version to connect with
65+
--apiStrict Use strict API version mode
66+
--apiDeprecationErrors Fail deprecated commands for the specified API version
67+
68+
FLE Options:
69+
70+
--awsAccessKeyId [arg] AWS Access Key for FLE Amazon KMS
71+
--awsSecretAccessKey [arg] AWS Secret Key for FLE Amazon KMS
72+
--awsSessionToken [arg] Optional AWS Session Token ID
73+
--keyVaultNamespace [arg] database.collection to store encrypted FLE parameters
74+
--kmsURL [arg] Test parameter to override the URL of the KMS endpoint
75+
76+
DB Address Examples:
77+
78+
foo Foo database on local machine
79+
192.168.0.5/foo Foo database on 192.168.0.5 machine
80+
192.168.0.5:9999/foo Foo database on 192.168.0.5 machine on port 9999
81+
mongodb://192.168.0.5:9999/foo Connection string URI can also be used
82+
83+
File Names:
84+
85+
A list of files to run. Files must end in .js and will exit after unless --shell is specified.
86+
87+
Examples:
88+
89+
Start mongosh using 'ships' database on specified connection string:
90+
$ mongosh mongodb://192.168.0.5:9999/ships
91+
92+
For more information on usage: https://docs.mongodb.com/mongodb-shell.
93+
```
94+
95+
<!-- /AUTOMATICALLY_INSERT_CLI_USAGE -->

scripts/update-cli-usage-text.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env node
2+
'use strict';
3+
const fs = require('fs');
4+
const path = require('path');
5+
const child_process = require('child_process');
6+
7+
const usage = child_process.execFileSync(process.execPath, [path.resolve(__dirname, '..', 'packages', 'cli-repl', 'bin', 'mongosh.js'), '--help'],
8+
{encoding: 'utf8'})
9+
10+
for (const file of process.argv.slice(2)) {
11+
let contents = fs.readFileSync(file, 'utf8');
12+
contents = contents.replaceAll(/(<!--\s*AUTOMATICALLY_INSERT_CLI_USAGE\s*-->).*(<!--\s*\/AUTOMATICALLY_INSERT_CLI_USAGE\s*-->)/gs,
13+
(_match, p1, p2) => `${p1}\n\n\`\`\`shell${usage}\`\`\`\n\n${p2}`);
14+
fs.writeFileSync(file, contents);
15+
}

0 commit comments

Comments
 (0)