mirror of
https://github.com/lise-henry/crowbook
synced 2024-11-18 00:13:55 +01:00
allow --set to include a list of key value pairs, not just one
This commit is contained in:
parent
ec00827729
commit
aa156a349f
@ -78,23 +78,23 @@ lang: en
|
||||
`--set`
|
||||
-------
|
||||
|
||||
**usage**: `crowbook --set [KEY] [VALUE] <BOOK>`
|
||||
**usage**: `crowbook <BOOK> --set [KEY] [VALUE]...
|
||||
|
||||
This options allows to set or override a wide range an option normally
|
||||
defined in book configuration file. All valid option in the
|
||||
This options takes a list `KEY` `VALUE` pairs and allows to set or
|
||||
override a book configuration option. All valid options in the
|
||||
configuration files are valid as keys. For more information, see
|
||||
[the configuration file page](config.md).
|
||||
|
||||
### Examples ###
|
||||
|
||||
```
|
||||
$ crowbook --set html.css style.css foo.book
|
||||
$ crowbook foo.book --set html.css style.css
|
||||
```
|
||||
|
||||
will override the CSS for HTML generation to `style.css`.
|
||||
will override the CSS for HTML generation (the `html.css` key) to `style.css`.
|
||||
|
||||
```
|
||||
$ crowbook --set author Foo --title Bar foo.book
|
||||
$ crowbook foo.book --set author Foo --title Bar
|
||||
```
|
||||
|
||||
will override the book title to `Bar` and its author to `Foo`.
|
||||
@ -152,5 +152,3 @@ $ crowbook foo/bar.book --to pdf --output baz.pdf
|
||||
```
|
||||
will thus generate `baz.pdf` in directory `foo` and not in current
|
||||
directory.
|
||||
|
||||
|
||||
|
@ -60,8 +60,8 @@ will thus generate baz.pdf in directory foo and not in current directory.")
|
||||
.index(2))
|
||||
.arg(Arg::from_usage("-t, --to [FORMAT] 'Generate specific format'")
|
||||
.possible_values(&["epub", "pdf", "html", "tex", "odt"]))
|
||||
.arg(Arg::from_usage("-s, --set [KEY] [VALUE] 'Sets a book option.'")
|
||||
.multiple(true))
|
||||
.arg(Arg::from_usage("-s, --set [KEY_VALUES] 'Sets a list of book options'")
|
||||
.min_values(2))
|
||||
.arg(Arg::with_name("BOOK")
|
||||
.index(1)
|
||||
.required(true)
|
||||
|
@ -89,11 +89,21 @@ fn render_format(book: &mut Book, matches: &ArgMatches, format: &str) -> ! {
|
||||
fn set_book_options(book: &mut Book, matches: &ArgMatches) {
|
||||
if let Some(iter) = matches.values_of("set") {
|
||||
let v:Vec<_> = iter.collect();
|
||||
let key = v[0];
|
||||
let value = v[1];
|
||||
let res = book.set_option(key, value);
|
||||
if let Err(err) = res {
|
||||
print_error(&format!("Error in setting key {}: {}", key, err));
|
||||
println!("{:?}", v);
|
||||
|
||||
if v.len() %2 != 0 {
|
||||
print_error("An odd number of arguments was passed to --set, but it takes a list of key value pairs.");
|
||||
}
|
||||
|
||||
for i in 0..v.len()/2 {
|
||||
let key = v[i * 2];
|
||||
let value = v[i * 2 + 1];
|
||||
println!("setting {} to {}", key, value);
|
||||
|
||||
let res = book.set_option(key, value);
|
||||
if let Err(err) = res {
|
||||
print_error(&format!("Error in setting key {}: {}", key, err));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user