Skip to content
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

refactor : has module uses profile impl. #25

Merged
merged 1 commit into from
Oct 4, 2020

Conversation

UsairimIsani
Copy link
Contributor

Progresses issues #17

@rusty-snake

Copy link
Owner

@rusty-snake rusty-snake left a comment

Choose a reason for hiding this comment

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

This currently checks if the file can be read. A simple check whether the file exists, can be done like this.

let profile = Profile::new(profile_name, ProfileFlags::default()).unwrap(); // We could also exclude LOOKUP_CWD if we want.
if let Some(path) = profile.path() {
...

Have you suggestions for the profile::Profile docs to make them easier, so other people can understand the concept of how to use profile::Profile the best way?

@UsairimIsani
Copy link
Contributor Author

This currently checks if the file can be read. A simple check whether the file exists, can be done like this.

let profile = Profile::new(profile_name, ProfileFlags::default()).unwrap(); // We could also exclude LOOKUP_CWD if we want.
if let Some(path) = profile.path() {
...

Have you suggestions for the profile::Profile docs to make them easier, so other people can understand the concept of how to use profile::Profile the best way?

The reason I chose to read the profile was, if I read it I know that it exists and has a valid path.

image

The suggested Implementation leads to panics if the file doesn't exist.
image

image

@rusty-snake
Copy link
Owner

The reason I chose to read the profile was, if I read it I know that it exists and has a valid path.

profile::lookup_profile which is called by profile::Profile::new already checks if a file exists (if called w/o ASSUME_EXISTENCE). On your screenshot are only the flags changed, but not the match/if let.

let flags = ProfileFlags::default();
match Profile::new(profile_name, flags) {
    Ok(profile) => ...,
    Err(err) => unreachable!("Profile::new always returns Ok(_) if called w/o READ flag ATM"),
}

What I suggested:

let flags = ProfileFlags::default();
match Profile::new(profile_name, flags).unwrap().path() {
    Some(path) => // found at path,
    None => // not found,
}

@UsairimIsani
Copy link
Contributor Author

image

Does this look ok? @rusty-snake

@rusty-snake
Copy link
Owner

The profile thing yes. However IMHO it should use println!. info! and error! are for logging. Imagine RUST_LOG is set to error (default in fjp is info, but env_logger has warn as default), a user would get the requested info only if it is "not found". Or we implement a --log-to-file command-line argument later.

(https://rust-lang.github.io/rust-clippy/rust-1.46.0/index.html#single_match_else if you want.)

refactor : logs in has mod.
@rusty-snake rusty-snake merged commit e738f23 into rusty-snake:master Oct 4, 2020
@rusty-snake
Copy link
Owner

Thanks for this contribution!

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