-
Notifications
You must be signed in to change notification settings - Fork 481
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
#340 Allow justfile without workdir #355
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.
Thank you for the patch! I have a few suggestions for how to avoid some unwraps.
I think this needs a test that ensures that the correct working directory is chosen. Would you like to take a stab at writing one? You can check out the existing tests in the tests
directory for ideas. I'm also happy to write it myself.
src/run.rs
Outdated
@@ -1,6 +1,6 @@ | |||
use common::*; | |||
|
|||
use std::{convert, ffi}; | |||
use std::{convert, ffi }; |
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.
It looks like this change isn't needed.
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.
Corrected extra space.
src/run.rs
Outdated
@@ -86,8 +86,7 @@ pub fn run() { | |||
.short("f") | |||
.long("justfile") | |||
.takes_value(true) | |||
.help("Use <JUSTFILE> as justfile. --working-directory must also be set") | |||
.requires("WORKING-DIRECTORY")) | |||
.help("Use <JUSTFILE> as justfile. --working-directory can be set [default: supplied justfile location]")) |
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 think that since the behavior of just in setting the working directory is the same as normal when using this flag, we can make the comment shorter. Just Use <JUSTFILE> as justfile.
is fine.
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.
Done.
src/run.rs
Outdated
@@ -187,7 +186,12 @@ pub fn run() { | |||
.collect::<Vec<&str>>(); | |||
|
|||
let justfile_option = matches.value_of("JUSTFILE"); | |||
let working_directory_option = matches.value_of("WORKING-DIRECTORY"); | |||
let mut working_directory_option = matches.value_of("WORKING-DIRECTORY"); |
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.
Let's change working_directory_option
to a Option<&Path>
, so that we're working with paths from here on out, and don't have to convert to a string. You can do .map(Path::new)
.
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.
Done.
src/run.rs
Outdated
let working_directory_option = matches.value_of("WORKING-DIRECTORY"); | ||
let mut working_directory_option = matches.value_of("WORKING-DIRECTORY"); | ||
|
||
if justfile_option.is_some() && working_directory_option.is_none() { |
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.
Let's change this to an if let
, so we can avoid the unwraps:
if let (Some(justfile), None) = (justfile_option, working_directory_option) {
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.
Done.
src/run.rs
Outdated
let mut working_directory_option = matches.value_of("WORKING-DIRECTORY"); | ||
|
||
if justfile_option.is_some() && working_directory_option.is_none() { | ||
let justfile_path = Path::new(justfile_option.unwrap()).parent(); |
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.
If parent()
returns none, we should exit with a message, like die!("Could not find parent directory of justfile at
{}", justfile)
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.
Added none check. But there seems to be a known issue(rust-lang/rust#36861) with parent returning "" in certain cases. Please suggest if it can be handled in a better way.
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.
Thanks for the changes! Let's resolve the justfile to an absolute path, and then using the parent of that.
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.
That should fix the issue with parent returning ""
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.
Disclaimer: I am very new to Rust :-), and although I understand reference concept, not able to find a 'Rust way' to deal with following situation and so having trouble with the code:
if let (Some(justfile), None) = (justfile_option, working_directory_option) {
let justfile_path = Path::new(justfile);
if Path::new(justfile).is_absolute() {
working_directory_option = Path::new(justfile).parent().unwrap().to_str();
} else {
let justfile_path_canonical = justfile_path.canonicalize();
if justfile_path.canonicalize().is_ok() {
// @casey following line errors out with borrowed value does not live long enough. Any suggestion?
working_directory_option = justfile_path_canonical.ok().unwrap().to_str();
} else {
die!("Could not find parent directory of justfile at {}.", justfile);
}
}
//println!("working_directory_option:{:?}", working_directory_option);
}
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.
No worries at all, we were all new to Rust once :)
Can you push the code (even if it's broken) to the PR branch so I can try it out?
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.
Done. It's broken.
I changed it to turn |
This will need a full integration test, i.e. a test that makes sure that the working directory is correct when |
Just added a test and landed this in #392. Thank you for contributing! |
#340 Making --working-directory optional for --justfile and --edit.