Skip to content

Commit 6d66d0e

Browse files
authored
fix(cli): make the scan command npx compatible (#92)
1 parent db5dbd5 commit 6d66d0e

File tree

4 files changed

+552
-531
lines changed

4 files changed

+552
-531
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ npm i
1717

1818
### Running a local scan
1919

20-
To run a scan on a host, a command line script `scan` is available. It returns the a JSON of the form described below. For example, to scan `mdn.dev`:
20+
To run a scan on a host, a command line script is available. It returns the a JSON of the form described below. For example, to scan `mdn.dev`:
2121

2222
```sh
23-
./scan mdn.dev
23+
npx mdn-http-observatory-scan mdn.dev
2424

2525
{
2626
"scan": {
@@ -47,9 +47,10 @@ To run a scan on a host, a command line script `scan` is available. It returns t
4747
...
4848
}
4949
}
50-
5150
```
5251

52+
To install the CLI script globally on your machine, run `npm install -g .` from the project root. `mdn-http-observatory-scan` is then available in your shell.
53+
5354
### Running a local API server
5455

5556
This needs a [postgres](https://www.postgresql.org/) database for the API to use as a persistence layer. All scans and results initiated via the API are stored in the database.

src/cli/index.js renamed to bin/scan.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
#!/usr/bin/env node
2+
13
import { Command } from "commander";
2-
import { scan } from "../scanner/index.js";
3-
const program = new Command();
4+
import { scan } from "../src/scanner/index.js";
45

5-
program
6-
.name("observatory")
7-
.description("CLI for the MDN HTTP Observatory")
8-
.version("1.0.0");
6+
const NAME = "mdn-http-observatory-scan";
7+
const program = new Command();
98

109
program
11-
.command("scan")
12-
.description("Scan a host")
13-
.argument("<string>", "hostname to scan")
10+
.name(NAME)
11+
.description("CLI for the MDN HTTP Observatory scan functionality")
12+
.version("1.0.0")
13+
.argument("<hostname>", "hostname to scan")
1414
.action(async (hostname, _options) => {
1515
try {
1616
const result = await scan(hostname);

0 commit comments

Comments
 (0)