-
Notifications
You must be signed in to change notification settings - Fork 286
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
Conversation
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.
LGTM 👍
Just some small notes/suggestions.
|
||
if !is_git_installed() { | ||
return Err(Error::GitNotInstalled); | ||
return Err("Git failed to execute!".into()); |
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.
Just some syntactic sugar:
I believe return Err(expression.into());
is equivalent to Err(expression)?
.
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>, | ||
} |
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.
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.
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'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.
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.
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 realOption
struct.
Also, the structopt::StructOpt
trait can be implemented on a wrapper struct for these fields.
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.
Also, the structopt::StructOpt trait can be implemented on a wrapper struct for these fields.
Great Idea, I may try it in another PR.
src/onefetch/language.rs
Outdated
$( Language::$name => include_str!(concat!("../../resources/", $ascii)), )* | ||
Language::Unknown => include_str!("../../resources/unknown.ascii"), |
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.
Cargo sets the CARGO_MANIFEST_DIR
environment variable, which for this project is the project root.
$( 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.
src/onefetch/language.rs
Outdated
@@ -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)); |
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.
const ASCII: &str = include_str!(concat!("../../resources/", $ascii)); | |
const ASCII: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/resources/", $ascii)); |
src/onefetch/language.rs
Outdated
@@ -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)); |
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.
const ASCII: &str = include_str!(concat!("../../resources/", $ascii)); | |
const ASCII: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/resources/", $ascii)); |
src/onefetch/license.rs
Outdated
|
||
static CACHE_DATA: &[u8] = include_bytes!("../resources/licenses/cache.bin.zstd"); | ||
static CACHE_DATA: &[u8] = include_bytes!("../../resources/licenses/cache.bin.zstd"); |
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.
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")); |
Did a bit of cleaning/refactoring. Starting with the
main.rs
module. I extracted theonefetch -h
part intocli.rs
. I also created anOption
struct that holds the input config and pass it along toInfo.rs
's constructor.Next step will be to refactor
Info.rs
...hopefully before it breaks the 1000 line barrier 😎