Skip to content

Commit fb76852

Browse files
authored
Automatically maintain HELP.md for the CLI (#402)
1 parent df35dec commit fb76852

File tree

7 files changed

+333
-7
lines changed

7 files changed

+333
-7
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,7 @@ indent_size = unset
4242
[LICENSE-APACHE.txt]
4343
indent_size = unset
4444
indent_style = unset
45+
46+
[HELP.md]
47+
max_line_length = 400
48+
trim_trailing_whitespace = false

Cargo.lock

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

HELP.md

Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
# Command-Line Help for `butane`
2+
3+
This document contains the help content for the `butane` command-line program.
4+
5+
**Command Overview:**
6+
7+
* [`butane`](#butane)
8+
* [`butane init`](#butane-init)
9+
* [`butane backend`](#butane-backend)
10+
* [`butane backend add`](#butane-backend-add)
11+
* [`butane backend remove`](#butane-backend-remove)
12+
* [`butane backend list`](#butane-backend-list)
13+
* [`butane make-migration`](#butane-make-migration)
14+
* [`butane detach-migration`](#butane-detach-migration)
15+
* [`butane migrate`](#butane-migrate)
16+
* [`butane regenerate`](#butane-regenerate)
17+
* [`butane describe-migration`](#butane-describe-migration)
18+
* [`butane list`](#butane-list)
19+
* [`butane collapse`](#butane-collapse)
20+
* [`butane embed`](#butane-embed)
21+
* [`butane unmigrate`](#butane-unmigrate)
22+
* [`butane clear`](#butane-clear)
23+
* [`butane clear data`](#butane-clear-data)
24+
* [`butane delete`](#butane-delete)
25+
* [`butane delete table`](#butane-delete-table)
26+
* [`butane clean`](#butane-clean)
27+
28+
## `butane`
29+
30+
Manages butane database migrations.
31+
32+
**Usage:** `butane [OPTIONS] <COMMAND>`
33+
34+
###### **Subcommands:**
35+
36+
* `init` — Initialize the database
37+
* `backend` — Backends
38+
* `make-migration` — Create a new migration
39+
* `detach-migration` — Detach the latest migration
40+
* `migrate` — Apply migrations
41+
* `regenerate` — Regenerate migrations in place
42+
* `describe-migration`
43+
* `list` — List migrations
44+
* `collapse` — Replace all migrations with a single migration representing the current model state
45+
* `embed` — Embed migrations in the source code
46+
* `unmigrate` — Undo migrations. With no arguments, undoes the latest migration. If the name of a migration is specified, rolls back until that migration is the latest applied migration
47+
* `clear` — Clear
48+
* `delete` — Delete
49+
* `clean` — Clean current migration state. Deletes the current migration working state which is generated on each build. This can be used as a workaround to remove stale tables from the schema, as Butane does not currently auto-detect model removals. The next build will recreate with only tables for the extant models
50+
51+
###### **Options:**
52+
53+
* `-v`, `--verbose` — Increase logging verbosity
54+
* `-q`, `--quiet` — Decrease logging verbosity
55+
* `-p`, `--path <PATH>`
56+
57+
Default value: `<detected project containing .butane directory>`
58+
59+
60+
61+
## `butane init`
62+
63+
Initialize the database
64+
65+
**Usage:** `butane init [OPTIONS] <BACKEND> <CONNECTION>`
66+
67+
###### **Arguments:**
68+
69+
* `<BACKEND>` — Database connection string. Format depends on backend
70+
* `<CONNECTION>` — Database backend to use. 'sqlite' or 'pg'
71+
72+
###### **Options:**
73+
74+
* `--no-connect` — Do not connect to the database
75+
76+
Possible values: `true`, `false`
77+
78+
79+
80+
81+
## `butane backend`
82+
83+
Backends
84+
85+
**Usage:** `butane backend <COMMAND>`
86+
87+
###### **Subcommands:**
88+
89+
* `add` — Add a backend to existing migrations
90+
* `remove` — Remove a backend from existing migrations
91+
* `list` — List backends present in existing migrations
92+
93+
94+
95+
## `butane backend add`
96+
97+
Add a backend to existing migrations
98+
99+
**Usage:** `butane backend add <NAME>`
100+
101+
###### **Arguments:**
102+
103+
* `<NAME>` — Backend name to add
104+
105+
106+
107+
## `butane backend remove`
108+
109+
Remove a backend from existing migrations
110+
111+
**Usage:** `butane backend remove <NAME>`
112+
113+
###### **Arguments:**
114+
115+
* `<NAME>` — Backend name to remove
116+
117+
118+
119+
## `butane backend list`
120+
121+
List backends present in existing migrations
122+
123+
**Usage:** `butane backend list`
124+
125+
126+
127+
## `butane make-migration`
128+
129+
Create a new migration
130+
131+
**Usage:** `butane make-migration <NAME>`
132+
133+
###### **Arguments:**
134+
135+
* `<NAME>` — Name to use for the migration
136+
137+
138+
139+
## `butane detach-migration`
140+
141+
Detach the latest migration
142+
143+
**Usage:** `butane detach-migration`
144+
145+
This command removes the latest migration from the list of migrations and sets butane state to before the latest migration was created.
146+
147+
The removed migration is not deleted from file system.
148+
149+
This operation is the first step of the process of rebasing a migration onto other migrations that have the same original migration.
150+
151+
If the migration has not been manually edited, it can be automatically regenerated after being rebased. In this case, deleting the detached migration is often the best approach.
152+
153+
However if the migration has been manually edited, it will need to be manually re-attached to the target migration series after the rebase has been completed.
154+
155+
156+
157+
158+
## `butane migrate`
159+
160+
Apply migrations
161+
162+
**Usage:** `butane migrate [NAME]`
163+
164+
###### **Arguments:**
165+
166+
* `<NAME>` — Migration to migrate to
167+
168+
169+
170+
## `butane regenerate`
171+
172+
Regenerate migrations in place
173+
174+
**Usage:** `butane regenerate`
175+
176+
177+
178+
## `butane describe-migration`
179+
180+
**Usage:** `butane describe-migration <NAME>`
181+
182+
###### **Arguments:**
183+
184+
* `<NAME>` — Name of migration to be described, or `current`
185+
186+
187+
188+
## `butane list`
189+
190+
List migrations
191+
192+
**Usage:** `butane list`
193+
194+
195+
196+
## `butane collapse`
197+
198+
Replace all migrations with a single migration representing the current model state
199+
200+
**Usage:** `butane collapse <NAME>`
201+
202+
###### **Arguments:**
203+
204+
* `<NAME>` — Name to use for the new migration
205+
206+
207+
208+
## `butane embed`
209+
210+
Embed migrations in the source code
211+
212+
**Usage:** `butane embed`
213+
214+
215+
216+
## `butane unmigrate`
217+
218+
Undo migrations. With no arguments, undoes the latest migration. If the name of a migration is specified, rolls back until that migration is the latest applied migration
219+
220+
**Usage:** `butane unmigrate [NAME]`
221+
222+
###### **Arguments:**
223+
224+
* `<NAME>` — Migration to roll back to
225+
226+
227+
228+
## `butane clear`
229+
230+
Clear
231+
232+
**Usage:** `butane clear <COMMAND>`
233+
234+
###### **Subcommands:**
235+
236+
* `data` — Clear all data from the database. The schema is left intact, but all instances of all models (i.e. all rows of all tables defined by the models) are deleted
237+
238+
239+
240+
## `butane clear data`
241+
242+
Clear all data from the database. The schema is left intact, but all instances of all models (i.e. all rows of all tables defined by the models) are deleted
243+
244+
**Usage:** `butane clear data`
245+
246+
247+
248+
## `butane delete`
249+
250+
Delete
251+
252+
**Usage:** `butane delete <COMMAND>`
253+
254+
###### **Subcommands:**
255+
256+
* `table` — Clear all data from the database. The schema is left intact, but all instances of all models (i.e. all rows of all tables defined by the models) are deleted
257+
258+
259+
260+
## `butane delete table`
261+
262+
Clear all data from the database. The schema is left intact, but all instances of all models (i.e. all rows of all tables defined by the models) are deleted
263+
264+
**Usage:** `butane delete table <NAME>`
265+
266+
###### **Arguments:**
267+
268+
* `<NAME>` — Table name
269+
270+
271+
272+
## `butane clean`
273+
274+
Clean current migration state. Deletes the current migration working state which is generated on each build. This can be used as a workaround to remove stale tables from the schema, as Butane does not currently auto-detect model removals. The next build will recreate with only tables for the extant models
275+
276+
**Usage:** `butane clean`
277+
278+
279+
280+
<hr/>
281+
282+
<small><i>
283+
This document was generated automatically by
284+
<a href="https://crates.io/crates/clap-markdown"><code>clap-markdown</code></a>.
285+
</i></small>
286+

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ build :
1515
lint :
1616
$(CARGO) clippy --all-features -- -D warnings
1717

18-
lint-ci : doclint lint spellcheck check-fmt
18+
lint-ci : doclint lint spellcheck check-fmt update-help-md check-help-md
1919

2020
check : build doclint lint spellcheck check-fmt test
2121

@@ -36,6 +36,12 @@ check-fmt :
3636
$(CARGO_NIGHTLY) fmt --check
3737
editorconfig-checker
3838

39+
update-help-md :
40+
$(CARGO) run -p butane_cli --features clap-markdown,sqlite-bundled -q -- --markdown-help list > HELP.md
41+
42+
check-help-md :
43+
git diff --exit-code HELP.md
44+
3945
spellcheck :
4046
typos
4147

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ implementation detail to the API consumer.
1414
## Features
1515

1616
* Relational queries using Rust-like syntax (via `proc-macro`s)
17+
* CLI to manage and deploy migrations. See [HELP.md].
1718
* Automatic migrations without writing SQL (although the generated SQL
1819
may be hand-tuned if necessary)
1920
* Ability to embed migrations in Rust code (so that a library may easily bundle its migrations)

butane_cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ butane.workspace = true
3131
cargo_metadata = "0.23"
3232
chrono = { workspace = true }
3333
clap = { version = "4.1", features = ["derive", "string", "wrap_help"] }
34+
clap-markdown = { git = "https://github.com/jayvdb/clap-markdown", branch = "allow-passing-instance", optional = true }
3435
clap-verbosity-flag = "3.0"
3536
env_logger.workspace = true
3637
log.workspace = true

0 commit comments

Comments
 (0)