Skip to content

Split/Refacto main module #253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Oct 12, 2020
Merged

Split/Refacto main module #253

merged 14 commits into from
Oct 12, 2020

Conversation

o2sh
Copy link
Owner

@o2sh o2sh commented Oct 9, 2020

Did a bit of cleaning/refactoring. Starting with the main.rs module. I extracted the onefetch -h part into cli.rs. I also created an Option struct that holds the input config and pass it along to Info.rs 's constructor.

Next step will be to refactor Info.rs...hopefully before it breaks the 1000 line barrier 😎

@o2sh o2sh requested a review from spenserblack October 9, 2020 22:43
Copy link
Collaborator

@spenserblack spenserblack left a comment

Choose a reason for hiding this comment

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

LGTM 👍
Just some small notes/suggestions.


if !is_git_installed() {
return Err(Error::GitNotInstalled);
return Err("Git failed to execute!".into());
Copy link
Collaborator

@spenserblack spenserblack Oct 12, 2020

Choose a reason for hiding this comment

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

Just some syntactic sugar:
I believe return Err(expression.into()); is equivalent to Err(expression)?.

Comment on lines +11 to +23
pub struct Options {
pub path: String,
pub ascii_language: Language,
pub ascii_colors: Vec<String>,
pub disabled_fields: info_fields::InfoFieldOn,
pub no_bold: bool,
pub image: Option<DynamicImage>,
pub image_backend: Option<Box<dyn image_backends::ImageBackend>>,
pub no_merges: bool,
pub no_color_blocks: bool,
pub number_of_authors: usize,
pub excluded: Vec<String>,
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Considering CLI options are being represented as a struct, you might want to use the structopt crate, which could handle most of these options. Although that would require a bit of additional refactoring.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I'm not sure this syntax will be able to cover our needs (at least not in one go). Especially for the option's parameters that require post-processing like image-backend and disabled_fields. I could however use this syntax on a simplified Opt struct and then map it to the real Option struct.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, not saying using structopt is something to do for this PR. Just wanted to bring up the option before I forget it 😆. We may want to use it eventually just to remove the manual definition of all the clap args that then get mapped to this struct.

I could however use this syntax on a simplified Opt struct and then map it to the real Option struct.

Also, the structopt::StructOpt trait can be implemented on a wrapper struct for these fields.

Copy link
Owner Author

@o2sh o2sh Oct 12, 2020

Choose a reason for hiding this comment

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

Also, the structopt::StructOpt trait can be implemented on a wrapper struct for these fields.

Great Idea, I may try it in another PR.

Comment on lines 43 to 44
$( Language::$name => include_str!(concat!("../../resources/", $ascii)), )*
Language::Unknown => include_str!("../../resources/unknown.ascii"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Cargo sets the CARGO_MANIFEST_DIR environment variable, which for this project is the project root.

Suggested change
$( Language::$name => include_str!(concat!("../../resources/", $ascii)), )*
Language::Unknown => include_str!("../../resources/unknown.ascii"),
$( Language::$name => include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/resources/", $ascii)), )*
Language::Unknown => include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/resources/unknown.ascii")),

This way these lines won't have to be updated on future file moves.

@@ -78,7 +78,7 @@ macro_rules! define_languages {
#[test]
#[ignore]
fn [<$name:lower _width>] () {
const ASCII: &str = include_str!(concat!("../resources/", $ascii));
const ASCII: &str = include_str!(concat!("../../resources/", $ascii));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const ASCII: &str = include_str!(concat!("../../resources/", $ascii));
const ASCII: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/resources/", $ascii));

@@ -91,7 +91,7 @@ macro_rules! define_languages {
#[test]
#[ignore]
fn [<$name:lower _height>] () {
const ASCII: &str = include_str!(concat!("../resources/", $ascii));
const ASCII: &str = include_str!(concat!("../../resources/", $ascii));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const ASCII: &str = include_str!(concat!("../../resources/", $ascii));
const ASCII: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/resources/", $ascii));


static CACHE_DATA: &[u8] = include_bytes!("../resources/licenses/cache.bin.zstd");
static CACHE_DATA: &[u8] = include_bytes!("../../resources/licenses/cache.bin.zstd");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
static CACHE_DATA: &[u8] = include_bytes!("../../resources/licenses/cache.bin.zstd");
static CACHE_DATA: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/resources/licenses/cache.bin.zstd"));

@o2sh o2sh merged commit a2b0bfd into master Oct 12, 2020
@o2sh o2sh deleted the refacto-main branch November 4, 2020 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants