Skip to content

Commit 29d1c9c

Browse files
authored
Merge pull request #421 from NodeSecure/enhance-commands-docs
docs: enhance CLI commands & usage examples
2 parents ac9836d + 4fffd84 commit 29d1c9c

File tree

17 files changed

+137
-77
lines changed

17 files changed

+137
-77
lines changed

README.md

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,9 @@ or
5858
$ git clone https://github.com/NodeSecure/cli.git
5959
$ cd cli
6060

61-
# install NPM dependencies
6261
$ npm install
63-
64-
# run esbuild to bundle/compile front-end assets
62+
# bundle/compile front-end assets
6563
$ npm run build
66-
6764
$ npm link
6865
```
6966

@@ -77,32 +74,29 @@ $ nsecure auto express
7774
7875
## 👀 Usage example
7976

80-
To show the complete list of commands
81-
```bash
82-
$ nsecure --help
83-
```
84-
85-
---
86-
8777
```bash
88-
# Run an analysis on the current working dir (must have a package.json file).
78+
# Run a scan on the current working dir
79+
# Note: must have a package.json or node_modules directory
8980
$ nsecure cwd
9081

91-
# Run an analysis for a given 'npm' package (must be in the npm registry).
82+
# Run a scan on a remote 'npm' package
9283
$ nsecure from mocha
9384
```
9485

9586
Then a `nsecure-result.json` will be writted at the current CLI location. To open it on a web page just run
9687

9788
```bash
9889
$ nsecure open
99-
100-
# If you want to define a specific port use the --port option.
101-
$ nsecure open --port 8080
10290
```
10391

10492
### Command Documentation
10593

94+
The CLI includes built-in documentation accessible with the --help option:
95+
```bash
96+
$ nsecure --help
97+
$ nsecure <command> --help
98+
```
99+
106100
For complete details on each command, refer to the following documents:
107101

108102
- [`cwd`](./docs/cli/cwd.md)
@@ -117,8 +111,7 @@ For complete details on each command, refer to the following documents:
117111
- [`config create`](./docs/cli/config.md)
118112
- [`config`](./docs/cli/config.md)
119113

120-
121-
Each link redirects you to the complete documentation of the command, with additional details, options, and usage examples.
114+
Each link provides access to the full documentation for the command, including additional details, options, and usage examples.
122115

123116
## Private registry / Verdaccio
124117

bin/index.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,25 @@ defaultScannerCommand("cwd", { strategy: vulnera.strategies.GITHUB_ADVISORY })
4646
.describe(i18n.getTokenSync("cli.commands.cwd.desc"))
4747
.option("-n, --nolock", i18n.getTokenSync("cli.commands.cwd.option_nolock"), false)
4848
.option("-f, --full", i18n.getTokenSync("cli.commands.cwd.option_full"), false)
49-
.action(async(...options) => {
49+
.action(async(options) => {
5050
checkNodeSecureToken();
51-
await commands.scanner.cwd(...options);
51+
await commands.scanner.cwd(options);
5252
});
5353

54-
defaultScannerCommand("from <package>")
54+
defaultScannerCommand("from <spec>")
5555
.describe(i18n.getTokenSync("cli.commands.from.desc"))
56-
.action(async(...options) => {
56+
.action(async(spec, options) => {
5757
checkNodeSecureToken();
58-
await commands.scanner.from(...options);
58+
await commands.scanner.from(spec, options);
5959
});
6060

61-
defaultScannerCommand("auto [package]", { includeOutput: false, strategy: vulnera.strategies.GITHUB_ADVISORY })
61+
defaultScannerCommand("auto [spec]", { includeOutput: false, strategy: vulnera.strategies.GITHUB_ADVISORY })
6262
.describe(i18n.getTokenSync("cli.commands.auto.desc"))
6363
.option("-k, --keep", i18n.getTokenSync("cli.commands.auto.option_keep"), false)
64-
.action(commands.scanner.auto);
64+
.action(async(spec, options) => {
65+
checkNodeSecureToken();
66+
await commands.scanner.auto(spec, options);
67+
});
6568

6669
prog
6770
.command("open [json]")
@@ -70,12 +73,12 @@ prog
7073
.action(commands.http.start);
7174

7275
prog
73-
.command("verify [package]")
76+
.command("verify [spec]")
7477
.describe(i18n.getTokenSync("cli.commands.verify.desc"))
7578
.option("-j, --json", i18n.getTokenSync("cli.commands.verify.option_json"), false)
76-
.action(async(...options) => {
79+
.action(async(spec, options) => {
7780
checkNodeSecureToken();
78-
await commands.verify.main(...options);
81+
await commands.verify.main(spec, options);
7982
});
8083

8184
prog
@@ -120,7 +123,7 @@ function defaultScannerCommand(name, options = {}) {
120123
const { includeOutput = true, strategy = null } = options;
121124

122125
const cmd = prog.command(name)
123-
.option("-d, --depth", i18n.getTokenSync("cli.commands.option_depth"), 4)
126+
.option("-d, --depth", i18n.getTokenSync("cli.commands.option_depth"), Infinity)
124127
.option("--silent", i18n.getTokenSync("cli.commands.option_silent"), false);
125128

126129
if (includeOutput) {

docs/cli/auto.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,25 @@ The `auto` command combines the `cwd` and `from` commands to analyze and explore
55
## 📜 Syntax
66

77
```bash
8-
nsecure auto [spec]
8+
$ nsecure auto [spec]
9+
```
10+
11+
Omitting the `[spec]` option is equivalent to running the `cwd` and `open` commands together. If `[spec]` is provided, the `from` command will be used instead.
12+
13+
## 👀 Example
14+
15+
By default, when using the `auto` command, the JSON payload is deleted once the HTTP server is closed. If you want to keep the JSON file to share or re-open it later, simply add the `--keep` or `-k` option.
16+
17+
```bash
18+
$ nsecure auto --keep
919
```
1020

1121
## ⚙️ Available Options
1222

1323
| Name | Shortcut | Default Value | Description |
1424
|---|---|---|--|
15-
| `--depth` | `-d` | `4` | Specify the depth of dependency analysis. |
16-
| `--silent` | | | Suppress console output, making execution silent. |
25+
| `--depth` | `-d` | `Infinity` | Maximum tree depth to scan. |
26+
| `--silent` | | `false` | Suppress console output, making execution silent. |
1727
| `--output` | `-o` | `nsecure-result` | Specify the output file for the results. |
18-
| `--keep` | `-k` | `false` | Preserve temporary files after execution. |
28+
| `--vulnerabilityStrategy` | `-s` | github-advisory | Strategy used to fetch package vulnerabilities (see Vulnera [available strategy](https://github.com/NodeSecure/vulnera?tab=readme-ov-file#available-strategy)). |
29+
| `--keep` | `-k` | `false` | Preserve JSON payload after execution. |

docs/cli/config.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ The `config` command allows you to manage the `.nodesecurerc` configuration file
55
## 📜 Syntax
66

77
```bash
8-
nsecure config [sub-command] [options]
8+
$ nsecure config create [options]
9+
# OR
10+
$ nsecure config edit
911
```
1012

1113
## ⚙️ Available Options
@@ -19,4 +21,3 @@ nsecure config [sub-command] [options]
1921
### `edit` Sub-command
2022

2123
This sub-command does not have any specific options.
22-

docs/cli/cwd.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The `cwd` command scans the project in the current working directory using the `
55
## 📜 Syntax
66

77
```bash
8-
nsecure cwd [options]
8+
$ nsecure cwd [options]
99
```
1010

1111
## ⚙️ Available Options
@@ -14,6 +14,7 @@ nsecure cwd [options]
1414
|---|---|---|---|
1515
| `--nolock` | `-n` | `false` | Do not use a lock file (package-lock.json or yarn.lock) for the analysis. |
1616
| `--full` | `-f` | `false` | Perform a full analysis of the project, including all dependencies. |
17-
| `--depth` | `-d` | `4` | Specify the depth of dependency analysis. |
18-
| `--silent` | | | Suppress console output, making execution silent. |
17+
| `--depth` | `-d` | `Infinity` | Maximum tree depth to scan. |
18+
| `--silent` | | `false` | Suppress console output, making execution silent. |
1919
| `--output` | `-o` | `nsecure-result` | Specify the output file for the results. |
20+
| `--vulnerabilityStrategy` | `-s` | github-advisory | Strategy used to fetch package vulnerabilities (see Vulnera [available strategy](https://github.com/NodeSecure/vulnera?tab=readme-ov-file#available-strategy)). |

docs/cli/from.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,22 @@ The `from` command allows you to run a security analysis on a specific npm packa
55
## 📜 Syntax
66

77
```bash
8-
nsecure from <package> [options]
8+
$ nsecure from <spec> [options]
9+
```
10+
11+
## 👀 Example
12+
13+
Scanning version 3.0.0 of express and saving the result into `./express-report.json`
14+
15+
```bash
16+
$ nsecure from [email protected] -o express-report
917
```
1018

1119
## ⚙️ Available Options
1220

1321
| Name | Shortcut | Default Value | Description |
1422
|---|---|---|---|
15-
| `--depth` | `-d` | `4` | Specify the depth of dependency analysis. |
23+
| `--depth` | `-d` | `Infinity` | Maximum tree depth to scan. |
24+
| `--silent` | | `false` | Suppress console output, making execution silent. |
1625
| `--output` | `-o` | `nsecure-result` | Specify the output file for the results. |
17-
| `--silent` | | | Suppress console output, making execution silent. |
18-
26+
| `--vulnerabilityStrategy` | `-s` | github-advisory | Strategy used to fetch package vulnerabilities (see Vulnera [available strategy](https://github.com/NodeSecure/vulnera?tab=readme-ov-file#available-strategy)). |

docs/cli/images/lang.PNG

5.97 KB
Loading

docs/cli/images/scorecard.PNG

53.1 KB
Loading

docs/cli/images/summary.PNG

18.8 KB
Loading

docs/cli/images/verify.PNG

48 KB
Loading

0 commit comments

Comments
 (0)