Skip to content

Commit af12938

Browse files
authored
Generate Markdown documentation of the CLI (#35)
1 parent 2fc683e commit af12938

5 files changed

Lines changed: 317 additions & 11 deletions

File tree

‎.github/workflows/ci.yaml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ jobs:
4545
uses: giraffate/clippy-action@v1
4646
with:
4747
reporter: github-pr-check
48+
49+
md-docs:
50+
runs-on: ubuntu-latest
51+
name: stable / md-docs
52+
steps:
53+
- uses: actions/checkout@v4
54+
- name: Install stable
55+
uses: dtolnay/rust-toolchain@stable
56+
- name: Generate md docs
57+
run: cargo run --bin bh -- md docs > docs/CLI.md
58+
59+
- name: Check if new docs were generated
60+
run: |
61+
git diff --exit-code
4862
tests:
4963
runs-on: ubuntu-latest
5064
name: ubuntu / ${{ matrix.toolchain }}

‎Cargo.lock‎

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ clap_complete = { version = "^4" }
1919
uuid = "^1"
2020
serde_json = "^1"
2121
percent-encoding = "2.3.1"
22+
clap-markdown = "0.1.5"
2223

2324
[dev-dependencies]
2425
uuid = { version = "^1", features = ["v7"] }

‎docs/CLI.md‎

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
# Command-Line Help for `bh`
2+
3+
This document contains the help content for the `bh` command-line program.
4+
5+
**Command Overview:**
6+
7+
* [`bh`↴](#bh)
8+
* [`bh job`↴](#bh-job)
9+
* [`bh job artifact`↴](#bh-job-artifact)
10+
* [`bh job artifact download`↴](#bh-job-artifact-download)
11+
* [`bh job artifact delete`↴](#bh-job-artifact-delete)
12+
* [`bh job delete`↴](#bh-job-delete)
13+
* [`bh scan`↴](#bh-scan)
14+
* [`bh scan dispatch`↴](#bh-scan-dispatch)
15+
* [`bh blob`↴](#bh-blob)
16+
* [`bh blob download`↴](#bh-blob-download)
17+
* [`bh blob upload`↴](#bh-blob-upload)
18+
* [`bh runner`↴](#bh-runner)
19+
* [`bh runner registration`↴](#bh-runner-registration)
20+
* [`bh runner registration token`↴](#bh-runner-registration-token)
21+
* [`bh runner registration command`↴](#bh-runner-registration-command)
22+
* [`bh md`↴](#bh-md)
23+
* [`bh md docs`↴](#bh-md-docs)
24+
* [`bh completion`↴](#bh-completion)
25+
26+
## `bh`
27+
28+
BountyHub CLI
29+
30+
**Usage:** `bh [COMMAND]`
31+
32+
###### **Subcommands:**
33+
34+
* `job` — Job related commands
35+
* `scan` — Scan related commands
36+
* `blob` — Blob related commands
37+
* `runner` — Runner related commands
38+
* `md` —
39+
* `completion` — Shell completion commands
40+
41+
42+
43+
## `bh job`
44+
45+
Job related commands
46+
47+
**Usage:** `bh job <COMMAND>`
48+
49+
###### **Subcommands:**
50+
51+
* `artifact` — Job artifact related commands
52+
* `delete` — Delete a job
53+
54+
55+
56+
## `bh job artifact`
57+
58+
Job artifact related commands
59+
60+
**Usage:** `bh job artifact <COMMAND>`
61+
62+
###### **Subcommands:**
63+
64+
* `download` — Download a file from the internet
65+
* `delete` — Delete job artifact
66+
67+
68+
69+
## `bh job artifact download`
70+
71+
Download a file from the internet
72+
73+
**Usage:** `bh job artifact download [OPTIONS] --job-id <JOB_ID> --artifact-name <ARTIFACT_NAME>`
74+
75+
###### **Options:**
76+
77+
* `-j`, `--job-id <JOB_ID>`
78+
* `-a`, `--artifact-name <ARTIFACT_NAME>`
79+
* `-o`, `--output <OUTPUT>`
80+
81+
82+
83+
## `bh job artifact delete`
84+
85+
Delete job artifact
86+
87+
**Usage:** `bh job artifact delete --job-id <JOB_ID> --artifact-name <ARTIFACT_NAME>`
88+
89+
###### **Options:**
90+
91+
* `-j`, `--job-id <JOB_ID>`
92+
* `-a`, `--artifact-name <ARTIFACT_NAME>`
93+
94+
95+
96+
## `bh job delete`
97+
98+
Delete a job
99+
100+
**Usage:** `bh job delete --job-id <JOB_ID>`
101+
102+
###### **Options:**
103+
104+
* `-j`, `--job-id <JOB_ID>`
105+
106+
107+
108+
## `bh scan`
109+
110+
Scan related commands
111+
112+
**Usage:** `bh scan <COMMAND>`
113+
114+
###### **Subcommands:**
115+
116+
* `dispatch` — Dispatch a scan from the latest revision of the workflow
117+
118+
119+
120+
## `bh scan dispatch`
121+
122+
Dispatch a scan from the latest revision of the workflow
123+
124+
**Usage:** `bh scan dispatch [OPTIONS] --workflow-id <WORKFLOW_ID> --scan-name <SCAN_NAME>`
125+
126+
###### **Options:**
127+
128+
* `-w`, `--workflow-id <WORKFLOW_ID>`
129+
* `-s`, `--scan-name <SCAN_NAME>`
130+
* `--input-string <INPUT_STRING>`
131+
* `--input-bool <INPUT_BOOL>`
132+
133+
134+
135+
## `bh blob`
136+
137+
Blob related commands
138+
139+
**Usage:** `bh blob <COMMAND>`
140+
141+
###### **Subcommands:**
142+
143+
* `download` — Download a file from bountyhub.org blob storage
144+
* `upload` — Upload a file to bountyhub.org blob storage
145+
146+
147+
148+
## `bh blob download`
149+
150+
Download a file from bountyhub.org blob storage
151+
152+
**Usage:** `bh blob download [OPTIONS] --src <SRC>`
153+
154+
###### **Options:**
155+
156+
* `-s`, `--src <SRC>`
157+
* `-d`, `--dst <DST>`
158+
159+
160+
161+
## `bh blob upload`
162+
163+
Upload a file to bountyhub.org blob storage
164+
165+
**Usage:** `bh blob upload --src <SRC> --dst <DST>`
166+
167+
###### **Options:**
168+
169+
* `-s`, `--src <SRC>` — src is the source file on the local filesystem
170+
* `--dst <DST>` — dst is the destination path on bountyhub.org blobs
171+
172+
173+
174+
## `bh runner`
175+
176+
Runner related commands
177+
178+
**Usage:** `bh runner <COMMAND>`
179+
180+
###### **Subcommands:**
181+
182+
* `registration` — Runner registration commands
183+
184+
185+
186+
## `bh runner registration`
187+
188+
Runner registration commands
189+
190+
**Usage:** `bh runner registration <COMMAND>`
191+
192+
###### **Subcommands:**
193+
194+
* `token` — Get newly created runner registration token
195+
* `command` — Get runner registration command with newly created token
196+
197+
198+
199+
## `bh runner registration token`
200+
201+
Get newly created runner registration token
202+
203+
**Usage:** `bh runner registration token`
204+
205+
206+
207+
## `bh runner registration command`
208+
209+
Get runner registration command with newly created token
210+
211+
**Usage:** `bh runner registration command`
212+
213+
214+
215+
## `bh md`
216+
217+
**Usage:** `bh md <COMMAND>`
218+
219+
###### **Subcommands:**
220+
221+
* `docs` — Generate markdown documentation for the CLI
222+
223+
224+
225+
## `bh md docs`
226+
227+
Generate markdown documentation for the CLI
228+
229+
**Usage:** `bh md docs`
230+
231+
232+
233+
## `bh completion`
234+
235+
Shell completion commands
236+
237+
**Usage:** `bh completion <SHELL>`
238+
239+
###### **Arguments:**
240+
241+
* `<SHELL>`
242+
243+
Possible values: `bash`, `elvish`, `fish`, `powershell`, `zsh`
244+
245+
246+
247+
248+
<hr/>
249+
250+
<small><i>
251+
This document was generated automatically by
252+
<a href="https://crates.io/crates/clap-markdown"><code>clap-markdown</code></a>.
253+
</i></small>
254+

‎src/cli.rs‎

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,35 @@ enum Commands {
5656
#[command(subcommand)]
5757
Runner(Runner),
5858

59+
#[command(subcommand)]
60+
Md(Md),
61+
5962
/// Shell completion commands
6063
#[command(arg_required_else_help = true)]
6164
Completion(Completion),
6265
}
6366

6467
impl Commands {
6568
fn run(self) -> Result<()> {
66-
if let Commands::Completion(completion) = self {
67-
completion.run()?;
68-
return Ok(());
69-
}
70-
71-
let client = new_client()?;
7269
match self {
73-
Commands::Completion(_) => unreachable!(),
74-
Commands::Job(job) => job.run(client)?,
75-
Commands::Scan(scan) => scan.run(client)?,
76-
Commands::Runner(runner) => runner.run(client)?,
77-
Commands::Blob(blob) => blob.run(client)?,
70+
Commands::Md(md) => md.run()?,
71+
Commands::Completion(completion) => completion.run()?,
72+
Commands::Job(job) => {
73+
let client = new_client()?;
74+
job.run(client)?
75+
}
76+
Commands::Scan(scan) => {
77+
let client = new_client()?;
78+
scan.run(client)?
79+
}
80+
Commands::Runner(runner) => {
81+
let client = new_client()?;
82+
runner.run(client)?
83+
}
84+
Commands::Blob(blob) => {
85+
let client = new_client()?;
86+
blob.run(client)?
87+
}
7888
}
7989

8090
Ok(())
@@ -595,6 +605,23 @@ mod job_tests {
595605
}
596606
}
597607

608+
#[derive(Subcommand, Debug)]
609+
enum Md {
610+
#[command(about = "Generate markdown documentation for the CLI")]
611+
Docs,
612+
}
613+
614+
impl Md {
615+
fn run(&self) -> Result<()> {
616+
match self {
617+
Md::Docs => {
618+
clap_markdown::print_help_markdown::<Cli>();
619+
}
620+
}
621+
Ok(())
622+
}
623+
}
624+
598625
#[derive(Args, Debug)]
599626
struct Completion {
600627
#[arg(value_enum)]

0 commit comments

Comments
 (0)