This repository has been archived by the owner on Jun 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from ebcrowder/fs
Restructuring
- Loading branch information
Showing
17 changed files
with
734 additions
and
1,075 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "rust_ledger" | ||
version = "0.2.0" | ||
version = "0.3.0" | ||
authors = ["ebcrowder <[email protected]>"] | ||
edition = "2018" | ||
license = "GPL-3.0" | ||
|
@@ -11,14 +11,9 @@ repository = "https://github.com/ebcrowder/rust_ledger" | |
readme = "README.md" | ||
|
||
[dependencies] | ||
serde_yaml = "0.8.12" | ||
serde = { version = "1.0.110", features = ["derive"] } | ||
serde_yaml = "0.8.13" | ||
serde = { version = "1.0.114", features = ["derive"] } | ||
csv = "1.1.3" | ||
pargs = "0.1.4" | ||
colored = "1.9.3" | ||
colored = "2.0.0" | ||
monee = "0.0.5" | ||
|
||
[dev-dependencies] | ||
assert_cmd = "1.0.1" | ||
predicates = "1.0.4" | ||
tempfile = "3.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
mod account; | ||
mod balance; | ||
mod csv; | ||
mod register; | ||
|
||
use crate::error::{Error, Result}; | ||
use pargs; | ||
use std::env; | ||
|
||
pub fn run() -> Result<()> { | ||
let args: Vec<String> = env::args().collect(); | ||
|
||
// define expected args for pargs | ||
let command_args: Vec<String> = vec![ | ||
String::from("account"), | ||
String::from("balance"), | ||
String::from("register"), | ||
String::from("csv"), | ||
]; | ||
let flag_args: Vec<String> = vec![]; | ||
let option_args: Vec<String> = vec![String::from("-l"), String::from("-f")]; | ||
|
||
// pargs will parse the args and return the result | ||
let pargs_result = pargs::parse(args, command_args, flag_args, option_args)?; | ||
|
||
let pargs_options = pargs_result.option_args; | ||
let pargs_commands = pargs_result.command_args; | ||
|
||
let ledger_file = match pargs_options.get("-l") { | ||
Some(value) => value.to_string(), | ||
None => { | ||
let ledger_file_env = match std::env::var("RLEDGER_FILE") { | ||
Ok(p) => format!("{}", p), | ||
Err(err) => format!("{}", err), | ||
}; | ||
|
||
ledger_file_env.to_string() | ||
} | ||
}; | ||
|
||
let options_arg = match pargs_options.get("-f") { | ||
Some(value) => value, | ||
None => "", | ||
}; | ||
|
||
match &pargs_commands.len() { | ||
0 => Err(Error::InvalidArg("please enter a command.".to_string())), | ||
_ => match &pargs_commands[0][..] { | ||
"account" => account::account(&ledger_file.to_string()), | ||
"balance" => balance::balance(&ledger_file.to_string()), | ||
"register" => register::register(&ledger_file.to_string(), &options_arg.to_string()), | ||
"csv" => csv::csv(&ledger_file.to_string(), &options_arg.to_string()), | ||
_ => panic!("command not found.".to_string()), | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
extern crate serde_yaml; | ||
|
||
use crate::error::Result; | ||
use crate::model::ledger::LedgerFile; | ||
|
||
/// returns all general ledger accounts | ||
pub fn account(filename: &String) -> Result<()> { | ||
let file = std::fs::File::open(filename)?; | ||
let deserialized_file: LedgerFile = serde_yaml::from_reader(file).unwrap(); | ||
|
||
LedgerFile::print_accounts(deserialized_file); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
extern crate serde_yaml; | ||
|
||
use crate::error::Result; | ||
use crate::model::ledger::LedgerFile; | ||
|
||
/// returns balances of all general ledger accounts | ||
pub fn balance(filename: &String) -> Result<()> { | ||
let file = std::fs::File::open(filename)?; | ||
let deserialized_file: LedgerFile = serde_yaml::from_reader(file).unwrap(); | ||
|
||
LedgerFile::print_balances(deserialized_file); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
extern crate serde_yaml; | ||
|
||
use crate::error::Result; | ||
use crate::model::ledger::LedgerFile; | ||
|
||
/// returns all general ledger transactions | ||
pub fn register(filename: &String, option: &String) -> Result<()> { | ||
let file = std::fs::File::open(filename)?; | ||
let deserialized_file: LedgerFile = serde_yaml::from_reader(file).unwrap(); | ||
|
||
LedgerFile::print_register(deserialized_file, option); | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.