-
Notifications
You must be signed in to change notification settings - Fork 16
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
Shorten path names when --debug is not passed #20
Conversation
Ah, one more comment. I wasn't sure about this, you're moving away the config value for the canonicalized dir path, and pass that on. The Arg structure still contains the "unresolved" path, so I needed to pass on both. I don't know where you want to be going with this and what your design ideas are, but my suggestion would be to replace the Let me know if you want me to change that. |
@KillTheMule So sorry that I haven't taken a look at it yet! It's totally okay to @mention me if it looks like I've forgotten about something. Sadly merging #22 introduced some merge conflicts for this PR. I'll try to resolve them and the the PR merged ASAP! |
No worries :) If you have trouble, feel free to close this, I might be able to reproduce it on current master some time. |
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.
Hello and sorry for the long delay in reviewing. This looks on the right track, I just had a few nitpicks. Do you mind rebasing this and addressing the comments?
If you're up for a challenge, it would also be great to have tests for the new feature: I think tests/simple_project
would be a good place. You'll need to add a new broken link, then capture the output from cargo-deadlinks
and make sure it has the filename you expect.
src/check.rs
Outdated
if args.flag_debug { | ||
if path.exists() { | ||
debug!("{}: Linked file {} exists.", file.display(), path.display()); | ||
true | ||
} else { | ||
error!("{}: Linked file {} does not exist!", file.display(), path.display()); | ||
false | ||
} | ||
} else { | ||
error!("Linked file at path {} does not exist!", path.display()); | ||
false | ||
let shortpath = path.strip_prefix(base_dir).unwrap_or_else(|_| &path); | ||
let shortfile = file.strip_prefix(base_dir).unwrap_or_else(|_| &file); | ||
if path.exists() { | ||
debug!("{}: Linked file {} exists.", shortfile.display(), shortpath.display()); | ||
true | ||
} else { | ||
error!("{}: Linked file {} does not exist!", shortfile.display(), shortpath.display()); | ||
false | ||
} |
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.
Rather than duplicating this, can you lift the short*
variables out of the if? Something like
let shortpath = if !args.flag_debug {
file = file.strip_prefix(base_dir).unwrap_or(&file);
path.strip_prefix(base_dir).unwrap_or(&path)
} else {
path
};
Then you wouldn't need to write the path.exists()
if block twice.
src/main.rs
Outdated
@@ -42,7 +42,7 @@ Options: | |||
"; | |||
|
|||
#[derive(Debug, RustcDecodable)] | |||
struct MainArgs { | |||
pub struct MainArgs { |
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.
You don't need this to be pub
I think, check
is a submodule.
pub struct MainArgs { | |
struct MainArgs { |
src/main.rs
Outdated
@@ -56,9 +56,9 @@ fn main() { | |||
|
|||
init_logger(&args); | |||
|
|||
let dir = args.arg_directory.map_or_else(determine_dir, |dir| PathBuf::from(dir)); | |||
let dir = args.arg_directory.clone().map_or_else(determine_dir, |dir| PathBuf::from(dir)); |
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.
You can get rid of the clone()
if you change walk_dir
to take a boolean instead of all of MainArgs
. Alternatively you could change this to a &Path
instead of a PathBuf
.
Ha very cool! I‘ll Look into it, but It‘ll probably be next week or so. Thanks for your comments! |
Ok, I rewrote this, based on #80. It doesn't really need #80, so let me know if you want that, otherwise I'll just remove the change to the internal arg handling. I could use a hand on the test though, it passes locally, but seems like |
b5abf9a
to
117c396
Compare
(I'm going to address #80 here because I don't think it makes sense to merge independently of this.)
I would prefer not to make the arguments struct part of the library; most of them don't seem relevant to calling deadlinks programatically. I think it also makes sense to strip paths in the binary part of the project, not the library. So my suggested approach is to make this change in Line 174 in 117c396
Instead of printing the error directly, inspect the file path and call strip_path there, not in the library itself. That way, other people using deadlinks as a crate still have the absolute path if they need it. |
Ok, I changed the code so basically everything is handled in main, except we need to put the path into the error struct, and the debug flag in the context struct. The whole thing feels a tad clunky, because we're somewhat duplicating the printout code. I could make a method Tests pass locally, as I said, but not on CI, will still need help with that. |
Could you instead have a
Can you instead use the To avoid borrow-check errors, you may need to change |
Hmm, I can reproduce the failures both locally and on master ... let me look into that, not sure how it slipped past CI. |
The issue you're running into is that the tests can't run in parallel; The issue I hit was specific to |
Next round :) Inlined the test, and constructed the I didn't see how I could pass a formatter to |
Hmm, I don't understand that test failure (passes locally, of course...). The output correctly points out the missing I've been able to make this pass by expecting another file where the link is broken. Still feels brittle. |
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 didn't see how I could pass a formatter to print_shortened outside of the Display impl, so I had it return a String instead.
Sure, that seems fine.
Hmm, I don't understand that test failure (passes locally, of course...)
Are you using nightly locally? Intra-doc links won't be stable for another 4 weeks. Your current test looks fine though.
Overall this looks great :) Just a small nit then I think this is ready to go.
When --debug is given, still show the full path
Riiight, man, the things one forgets :D Works out then! |
Thanks so much for working on this! I'll try to get out a 0.4.2 release today so you can start using it right away :) |
Pleasure to do so, and thanks for your patient comments! |
Closes #19.
I did a bit more, now the output looks like
As you requested, I left the verbose output with the long file names. It's even longer now that I've added the origin of the checked link, but imho that's useful. You don't implement checking http urls, so I wasn't sure how to handle those things for http checking, so I stayed with simply passing along pathes.
I refrained from running rustfmt on it or doing any formatting on my own, so this can be reviewed more easily. Let me know if that floats your boat :)