Skip to content

Commit 2797966

Browse files
authored
docs(README): use --help text & Typo fixes (#141)
1 parent d307512 commit 2797966

File tree

5 files changed

+126
-24
lines changed

5 files changed

+126
-24
lines changed

Diff for: README.md

+122-20
Original file line numberDiff line numberDiff line change
@@ -105,32 +105,134 @@ Setting up a custom binary allows you to completely customize the generation; ho
105105
cargo install dsync
106106
```
107107

108-
**CLI Usage**
109-
110-
* `-i`: path to the diesel schema file
111-
* `-o`: model output directory
112-
* `-c`: connection type (for example: `diesel::sqlite::SqliteConnection`)
113-
* `-g`: (optional, repeatable) list of columns that are automatically generated by create/update triggers (for example, `created_at`, `updated_at`)
114-
* `--tsync`: (optional) adds `#[tsync]` attribute to generated structs for the [`tsync` crate](https://github.com/Wulf/tsync)
115-
* `--model-path`: (optional) set a custom model import path, default `crate::models::`
116-
* `--schema-path`: (optional) set a custom schema import path, default `crate::schema::`
117-
* `--no-serde`: (optional) if set, does not output any serde related code
118-
* `--no-crud`: (optional) Do not generate the CRUD functions for generated models
119-
* `--create-str`: (optional) Set which string type to use for `Create*` structs (possible are `string`, `str`, `cow`)
120-
* `--update-str`: (optional) Set which string type to use for `Update*` structs (possible are `string`, `str`, `cow`)
121-
* `--single-model-file`: (optional) Generate only a single model file, instead of a directory with `mod.rs` and `generated.rs`
122-
* `--readonly-prefix`: (optional, repeatable) A prefix to treat a table matching this as readonly *2
123-
* `--readonly-suffix`: (optional, repeatable) A suffix to treat a table matching this as readonly *2
124-
* `--diesel-backend`: (when the "advanced-queries" feature is enabled) The diesel backend in use (possible values include `diesel::pg::Pg`, `diesel::sqlite::Sqlite`, `diesel::mysql::Mysql`, or your custom backend type)
108+
### CLI Usage
125109

110+
```sh
111+
Generate rust structs & query functions from diesel schema files.
112+
113+
Usage: dsync [OPTIONS] --input <INPUT> --output <OUTPUT> --connection-type <CONNECTION_TYPE>
114+
dsync [OPTIONS] <COMMAND>
115+
116+
Commands:
117+
completions Generate shell completions
118+
119+
Options:
120+
-i, --input <INPUT>
121+
Input diesel schema file
122+
123+
-o, --output <OUTPUT>
124+
Output file, stdout if not present
125+
126+
--tsync
127+
adds the #[tsync] attribute to all structs; see
128+
https://github.com/Wulf/tsync
129+
130+
-g, --autogenerated-columns <AUTOGENERATED_COLUMNS>
131+
List of columns which are automatically generated but are not primary
132+
keys (for example: "created_at", "updated_at", etc.)
133+
134+
-c, --connection-type <CONNECTION_TYPE>
135+
rust type which describes a connection
136+
137+
For example:
138+
- `diesel::pg::PgConnection`
139+
- `diesel::sqlite::SqliteConnection`
140+
- `diesel::mysql::MysqlConnection`
141+
-
142+
`diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::pg::PgConnection>>`
143+
- or, your custom diesel connection type (struct which implements
144+
`diesel::connection::Connection`)
145+
146+
--no-serde
147+
Disable generating serde implementations
148+
149+
--schema-path <SCHEMA_PATH>
150+
Set custom schema use path
151+
152+
[default: crate::schema::]
153+
154+
--model-path <MODEL_PATH>
155+
Set custom model use path
156+
157+
[default: crate::models::]
158+
159+
--no-crud
160+
Do not generate the CRUD (impl) functions for generated models
161+
162+
--create-str <CREATE_STR>
163+
Set which string type to use for Create* structs
164+
165+
[default: string]
166+
167+
Possible values:
168+
- string: Use "String"
169+
- str: Use "&str"
170+
- cow: Use "Cow<str>"
171+
172+
--update-str <UPDATE_STR>
173+
Set which string type to use for Update* structs
174+
175+
[default: string]
176+
177+
Possible values:
178+
- string: Use "String"
179+
- str: Use "&str"
180+
- cow: Use "Cow<str>"
181+
182+
--create-bytes <CREATE_BYTES>
183+
Set which bytes type to use for Create* structs
184+
185+
[default: vec]
186+
187+
Possible values:
188+
- vec: Use "Vec<u8>"
189+
- slice: Use "&[u8]"
190+
- cow: Use "Cow<[u8]>"
191+
192+
--update-bytes <UPDATE_BYTES>
193+
Set which bytes type to use for Update* structs
194+
195+
[default: vec]
196+
197+
Possible values:
198+
- vec: Use "Vec<u8>"
199+
- slice: Use "&[u8]"
200+
- cow: Use "Cow<[u8]>"
201+
202+
--single-model-file
203+
Only Generate a single model file instead of a directory with "mod.rs"
204+
and "generated.rs"
205+
206+
--once-common-structs
207+
Generate common structs only once in a "common.rs" file
208+
209+
--once-connection-type
210+
Generate the "ConnectionType" type only once in a "common.rs" file
211+
212+
--readonly-prefix <READONLY_PREFIXES>
213+
A Prefix to treat a table matching this as readonly (only generate the
214+
Read struct)
215+
216+
--readonly-suffix <READONLY_SUFFIXES>
217+
A Suffix to treat a table matching this as readonly (only generate the
218+
Read struct)
219+
220+
-h, --help
221+
Print help (see a summary with '-h')
222+
223+
-V, --version
224+
Print version
225+
```
226+
227+
#### Example
126228
```sh
127229
dsync -i src/schema.rs -o src/models
128230
```
129231
130-
Notes:
232+
#### Notes
131233
132234
- the CLI has fail-safes to prevent accidental file overwriting
133-
- *2: "readonly" tables dont have `Update*`(`UpdateTodos`) & `Create*`(`CreateTodos`) structs, only `*`(`Todos`, no suffix / prefix) structs.
235+
- *2: "readonly" tables don't have `Update*`(`UpdateTodos`) & `Create*`(`CreateTodos`) structs, only `*`(`Todos`, no suffix / prefix) structs.
134236
For example this is useful for Sqlite views, which are read-only (cannot be written to, but can be read)
135237
136238
## Experimental API
@@ -139,7 +241,7 @@ We're currently experimenting with advanced query generation. This includes pagi
139241
140242
Alternatively, you can see what gets generated in the advanced queries test here: [`test/advanced_queries/models`](test/advanced_queries/models)
141243
142-
Feel free to open an issue to discuss these API and provide your feeedback.
244+
Feel free to open an issue to discuss these API and provide your feedback.
143245
144246
## Docs
145247

Diff for: src/code.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ fn get_async(table_options: &TableOptions<'_>) -> (&'static str, &'static str) {
427427
("", "")
428428
}
429429

430-
/// Generate all functions (insides of the `impl StuctName { here }`)
430+
/// Generate all functions (insides of the `impl StructName { here }`)
431431
fn build_table_fns(
432432
table: &ParsedTableMacro,
433433
config: &GenerationConfig,

Diff for: src/global.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub struct TableOptions<'a> {
101101
/// Only Generate a single model file instead of a directory with "mod.rs" and "generated.rs"
102102
single_model_file: bool,
103103

104-
/// Indiciates this table is meant to be read-only (dont generate Update & Create structs)
104+
/// Indicates this table is meant to be read-only (don't generate Update & Create structs)
105105
read_only: bool,
106106
}
107107

Diff for: src/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ fn handle_table_macro(
238238
let mut had_hashtag = false;
239239

240240
for column_tokens in group.stream().into_iter() {
241-
// reset "had_hastag" but still make it available for checking
241+
// reset "had_hashtag" but still make it available for checking
242242
let had_hashtag_last = had_hashtag;
243243
had_hashtag = false;
244244
match column_tokens {

Diff for: test/test_all.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ echo "Testing Generation"
1515
# extra separator
1616
echo ""
1717

18-
echo "Testing Compiliation"
18+
echo "Testing Compilation"
1919
./test_compile.sh

0 commit comments

Comments
 (0)