Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Restructuring #13

Merged
merged 20 commits into from
Jul 31, 2020
Merged

Restructuring #13

merged 20 commits into from
Jul 31, 2020

Conversation

ebcrowder
Copy link
Owner

@ebcrowder ebcrowder commented Jul 29, 2020

  • adds more robust logic for better error handling and messaging
  • moves the logic contained in the various modules into struct methods. This improves readability but also removes duplicate and unnecessary data structures.
  • rename the modules to singular verbs for consistency
  • replace integration tests with unit tests. Right now, the tests don't add a ton of value as they do not assert the stdout output but this is a good starting place. Besides, the previous tests did not add a lot of value, either.
  • compile times are much faster because we were able to drop hefty dev dependencies that were used by the integration tests.
  • dependency updates

@ebcrowder ebcrowder requested a review from dantuck July 31, 2020 02:00
@ebcrowder ebcrowder marked this pull request as ready for review July 31, 2020 02:00
@ebcrowder
Copy link
Owner Author

alrighty @dantuck - this is ready to go now.

Since it has been a while since I have published a version of this to crates.io, I'll do that after this gets merged.

Copy link
Collaborator

@dantuck dantuck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good. Nice work! I made a suggestion on the error result if you would like to take it. Other than that this looks like a good restructure.

As a follow up maybe we can chat about cleaning up the error output a little so that it doesn't look so programmer like:

➜  rust_ledger git:(fs) RLEDGER_FILE=examples/example.yal cargo run register 
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `target/debug/rust_ledger register`
Error: IOError(Os { code: 2, kind: NotFound, message: "No such file or directory" })

would become:

➜  rust_ledger git:(fs) RLEDGER_FILE=examples/example.yal cargo run register 
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `target/debug/rust_ledger register`
No such file or directory

Or something similar. I have been making some implementation changes to error output in another project that you could probably implement here.


// define expected args for pargs
let command_args: Vec<String> = vec![
String::from("account"),
Copy link
Collaborator

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.

use std::io;

extern crate csv;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add:

/// A type alias for `Result<T, Error>`.
pub type Result<T> = result::Result<T, Error>;

Which would allow you to change:

pub fn register(filename: &String, option: &String) -> Result<(), Error>

to

pub fn register(filename: &String, option: &String) -> Result 

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This a nice shortcut - thanks!

Comment on lines +5 to +6
fn main() -> Result<(), error::Error> {
cli::run()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And now that is CLEAN!

@ebcrowder
Copy link
Owner Author

Or something similar. I have been making some implementation changes to error output in another project that you could probably implement here.

Great - please do let me know what you find. I spent some time trying to figure out how to parse the default Error output but couldn't figure out a way to do it. I'm guessing the display() fn would be the place to do it.

I'll merge this in the meantime. Appreciate the quick review!

@ebcrowder ebcrowder merged commit 157d2ad into main Jul 31, 2020
@ebcrowder ebcrowder deleted the fs branch July 31, 2020 03:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants