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
Merged
Restructuring #13
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
5552282
init
ebcrowder 74c98e2
refactoring progress
ebcrowder 1433725
it compiles now
ebcrowder 4c86725
error refactoring
ebcrowder 38581a9
more progress
ebcrowder ae3d9ac
tests pass
ebcrowder 67d0797
mv dir
ebcrowder 5af5b80
impl block for account
ebcrowder fe62577
balance method
ebcrowder 4b92971
register impl method
ebcrowder 3d440e1
add error handling for pargs
ebcrowder 679c66c
readme edit for verb change
ebcrowder d5ce843
error tweaks
ebcrowder 48231d3
update error definitions
ebcrowder ad3795c
experimenting
ebcrowder f25a49c
rm integration tests
ebcrowder 66b6bd0
test acct reformat
ebcrowder e0ad59e
bump version
ebcrowder e03b636
update dependencies
ebcrowder 9a90790
result alias
ebcrowder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this change going to singular. Clean and consistent with the other commands.