mirror of
https://github.com/zaphar/kitchen.git
synced 2025-07-21 19:29:49 -04:00
Flag for CSV output
This commit is contained in:
parent
30b800ce09
commit
d47ddaba81
71
Cargo.lock
generated
71
Cargo.lock
generated
@ -18,6 +18,18 @@ version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||
|
||||
[[package]]
|
||||
name = "bstr"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
@ -48,6 +60,28 @@ dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "csv"
|
||||
version = "1.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1"
|
||||
dependencies = [
|
||||
"bstr",
|
||||
"csv-core",
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "csv-core"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.2"
|
||||
@ -59,20 +93,39 @@ dependencies = [
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "0.4.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
|
||||
|
||||
[[package]]
|
||||
name = "kitchen"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"csv",
|
||||
"recipes",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.93"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
|
||||
|
||||
[[package]]
|
||||
name = "num-bigint"
|
||||
version = "0.4.0"
|
||||
@ -125,6 +178,24 @@ dependencies = [
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.130"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913"
|
||||
|
||||
[[package]]
|
||||
name = "textwrap"
|
||||
version = "0.11.0"
|
||||
|
@ -8,6 +8,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
recipes = {path = "../recipes" }
|
||||
csv = "1.1.1"
|
||||
|
||||
[dependencies.clap]
|
||||
version = "2.33"
|
||||
|
@ -17,6 +17,8 @@ use std::io::Read;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::path::Path;
|
||||
|
||||
use csv;
|
||||
|
||||
use recipes::{parse, IngredientAccumulator, Recipe};
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -106,3 +108,17 @@ pub fn output_ingredients_list(rs: Vec<Recipe>) {
|
||||
println!(" {}", i.name);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn output_ingredients_csv(rs: Vec<Recipe>) {
|
||||
let mut acc = IngredientAccumulator::new();
|
||||
for r in rs {
|
||||
acc.accumulate_from(&r);
|
||||
}
|
||||
let out = std::io::stdout();
|
||||
let mut writer = csv::Writer::from_writer(out);
|
||||
for (_, i) in acc.ingredients() {
|
||||
writer
|
||||
.write_record(&[format!("{}", i.amt), i.name])
|
||||
.expect("Failed to write csv.");
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ where
|
||||
)
|
||||
(@subcommand groceries =>
|
||||
(about: "print out a grocery list for a set of recipes")
|
||||
(@arg csv: --csv "output ingredeints as csv")
|
||||
(@arg INPUT: +required "Input menu file to parse. One recipe file per line.")
|
||||
)
|
||||
)
|
||||
@ -57,7 +58,11 @@ fn main() {
|
||||
let menu_file = matches.value_of("INPUT").unwrap();
|
||||
match cli::read_menu_list(menu_file) {
|
||||
Ok(rs) => {
|
||||
cli::output_ingredients_list(rs);
|
||||
if matches.is_present("csv") {
|
||||
cli::output_ingredients_csv(rs);
|
||||
} else {
|
||||
cli::output_ingredients_list(rs);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("{:?}", e);
|
||||
|
Loading…
x
Reference in New Issue
Block a user