diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-07-29 15:42:12 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-07-29 16:25:47 +0200 |
| commit | 750ac56977cd08d850cf902c8c8070512ecf484f (patch) | |
| tree | a8a13634c0bc2dfe653ab52410c7c1a2f4c18dd1 | |
| parent | cf79a3180282f08a6165f4b88f52b78a14b9c688 (diff) | |
| download | money-750ac56977cd08d850cf902c8c8070512ecf484f.tar.gz | |
table output and show command
| -rw-r--r-- | cli/Cargo.lock | 31 | ||||
| -rw-r--r-- | cli/Cargo.toml | 1 | ||||
| -rw-r--r-- | cli/src/main.rs | 9 | ||||
| -rw-r--r-- | cli/src/transaction.rs | 12 |
4 files changed, 50 insertions, 3 deletions
diff --git a/cli/Cargo.lock b/cli/Cargo.lock index 3f79032..2a8bac4 100644 --- a/cli/Cargo.lock +++ b/cli/Cargo.lock @@ -120,6 +120,7 @@ dependencies = [ "serde", "serde_json", "structopt", + "tabled", "twox-hash", ] @@ -143,6 +144,15 @@ dependencies = [ ] [[package]] +name = "papergrid" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "117aab6154bbd707e4cca766c7df1d3d247f3bf3052a76709583713c356d6baf" +dependencies = [ + "unicode-width", +] + +[[package]] name = "proc-macro-error" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -281,6 +291,27 @@ dependencies = [ ] [[package]] +name = "tabled" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78e44c818a29312cb5f5b9b38aa72b37ad31b687dd32c5c50e737cc9f0385f20" +dependencies = [ + "papergrid", + "tabled_derive", +] + +[[package]] +name = "tabled_derive" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "295be2fd92b0c382818e4c5271594cd5232651ef3826c4e9963f204113eccec0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] name = "textwrap" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 0b5650a..e64608e 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -11,4 +11,5 @@ rust_decimal = { version = "1.15.0", features = ["serde-arbitrary-precision"] } serde = { version = "1.0.126", features = ["derive"] } serde_json = "1.0.64" structopt = "0.3.22" +tabled = "0.2.2" twox-hash = { version = "1.6.0", default-features = false } diff --git a/cli/src/main.rs b/cli/src/main.rs index 071e251..55279b1 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -3,6 +3,7 @@ use rust_decimal::Decimal; use std::path::PathBuf; use std::str::FromStr; use structopt::StructOpt; +use tabled::{Style, Table}; mod search; mod store; @@ -39,7 +40,8 @@ enum Command { }, List { target: ListTarget, - } + }, + Show, } #[derive(Debug)] @@ -70,9 +72,7 @@ fn main() { let mut store = Store::open(PathBuf::from("store")).unwrap(); let search = Search::new(store.transactions().iter().collect()); - println!("{:?}", search.get()); let search = search.subtract(Constraint::Category("a".to_string())); - println!("{:?}", search.get()); let args = Mn::from_args(); eprintln!("{:?}", args); @@ -107,5 +107,8 @@ fn main() { } => { println!("{}", store.categories().join("\n")); } + Command::Show => { + println!("{}", Table::new(store.transactions()).with(Style::psql())); + } } } diff --git a/cli/src/transaction.rs b/cli/src/transaction.rs index 117edfb..8e33aa4 100644 --- a/cli/src/transaction.rs +++ b/cli/src/transaction.rs @@ -2,10 +2,12 @@ use chrono::naive::NaiveDate; use rust_decimal::Decimal; use serde::{Deserialize, Serialize}; use std::convert::AsRef; +use std::fmt; use std::fs; use std::hash::{Hash, Hasher}; use std::path::Path; use structopt::StructOpt; +use tabled::Tabled; use twox_hash::XxHash64; pub(crate) type Account = String; @@ -33,9 +35,19 @@ impl std::str::FromStr for TransactionKind { } } +impl fmt::Display for TransactionKind { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + TransactionKind::Expense => write!(f, "expense"), + TransactionKind::Income => write!(f, "income"), + } + } +} + #[derive(Debug)] #[derive(Hash)] #[derive(Deserialize, Serialize)] +#[derive(Tabled)] pub struct Transaction { pub description: String, pub date: NaiveDate, |
