Add --justfile and --working-directory flags

This commit is contained in:
Casey Rodarmor 2016-10-23 19:56:30 -07:00
parent e8a4a82e4d
commit 92d231c2ec
2 changed files with 57 additions and 28 deletions

14
notes
View File

@ -14,6 +14,11 @@ notes
- just ../foo # ../justfile:foo - just ../foo # ../justfile:foo
- just xyz/foo # xyz/justfile:foo - just xyz/foo # xyz/justfile:foo
- just xyz/ # xyz/justfile:DEFAULT - just xyz/ # xyz/justfile:DEFAULT
- assignment
. export environment variables
. no barewords
- indentation is line continuation
- static errors when variables are missing {{}}, even if recipe isn't run
- change name back to 'just' - change name back to 'just'
. suggest j as alias . suggest j as alias
@ -35,6 +40,7 @@ notes
. habit of using clever commands and writing little scripts . habit of using clever commands and writing little scripts
. very low friction to write a script (no new file, chmod, add to rcs) . very low friction to write a script (no new file, chmod, add to rcs)
. make list of contributors, include travis . make list of contributors, include travis
. alias .j='just -j ~/.justfile -d ~'
- vim and emacs syntax hilighting (use makefile syntax hilighting for now) - vim and emacs syntax hilighting (use makefile syntax hilighting for now)
- split up code into modules for easier reading - split up code into modules for easier reading
. parsing . parsing
@ -48,11 +54,6 @@ notes
. r/rust . r/rust
later: later:
- indentation is line continuation
- assignment
. export environment variables
. no barewords
- static errors when variables are missing {{}}, even if recipe isn't run
- preludes: - preludes:
may be nice to allow all recipes in a given langauge to share may be nice to allow all recipes in a given langauge to share
functions, variables, etc. could have a "prelude" recipe functions, variables, etc. could have a "prelude" recipe
@ -60,8 +61,5 @@ later:
- windows support: currently calling 'sh', which won't work on windows - windows support: currently calling 'sh', which won't work on windows
the answer will probably be to write a 'sh' clone and to only the answer will probably be to write a 'sh' clone and to only
call binaries from cargo call binaries from cargo
- allow specifying justfile on command line with --justfile/-j
and dir with --directory/-d, so i can do:
alias .j='just -j ~/.justfile -d ~'
- run recipes asyncronously - run recipes asyncronously
- lint with clippy once it runs on stable - lint with clippy once it runs on stable

View File

@ -32,37 +32,68 @@ pub fn app() {
.short("s") .short("s")
.long("show") .long("show")
.takes_value(true) .takes_value(true)
.help("Show information about a recipe")) .value_name("recipe")
.help("Show information about <recipe>"))
.arg(Arg::with_name("working-directory")
.long("working-directory")
.takes_value(true)
.help("Use <working-directory> as working directory. --justfile must also be set"))
.arg(Arg::with_name("justfile")
.long("justfile")
.takes_value(true)
.help("Use <justfile> as justfile. --working-directory must also be set"))
.arg(Arg::with_name("recipe") .arg(Arg::with_name("recipe")
.multiple(true) .multiple(true)
.help("recipe(s) to run, defaults to the first recipe in the justfile")) .help("recipe(s) to run, defaults to the first recipe in the justfile"))
.get_matches(); .get_matches();
loop { // it is not obvious to me what we should do if only one of --justfile and
match fs::metadata("justfile") { // --working-directory are passed. refuse to run in that case to avoid
Ok(metadata) => if metadata.is_file() { break; }, // suprises.
Err(error) => { if matches.is_present("justfile") ^ matches.is_present("working-directory") {
if error.kind() != io::ErrorKind::NotFound { die!("--justfile and --working-directory may only be used together");
die!("Error fetching justfile metadata: {}", error) }
let justfile_option = matches.value_of("justfile");
let working_directory_option = matches.value_of("working-directory");
let text;
if let (Some(file), Some(directory)) = (justfile_option, working_directory_option) {
text = fs::File::open(file)
.unwrap_or_else(|error| die!("Error opening justfile: {}", error))
.slurp()
.unwrap_or_else(|error| die!("Error reading justfile: {}", error));
if let Err(error) = env::set_current_dir(directory) {
die!("Error changing directory to {}: {}", directory, error);
}
} else {
loop {
match fs::metadata("justfile") {
Ok(metadata) => if metadata.is_file() { break; },
Err(error) => {
if error.kind() != io::ErrorKind::NotFound {
die!("Error fetching justfile metadata: {}", error)
}
} }
} }
match env::current_dir() {
Ok(pathbuf) => if pathbuf.as_os_str() == "/" { die!("No justfile found."); },
Err(error) => die!("Error getting current dir: {}", error),
}
if let Err(error) = env::set_current_dir("..") {
die!("Error changing directory: {}", error);
}
} }
match env::current_dir() { text = fs::File::open("justfile")
Ok(pathbuf) => if pathbuf.as_os_str() == "/" { die!("No justfile found."); }, .unwrap_or_else(|error| die!("Error opening justfile: {}", error))
Err(error) => die!("Error getting current dir: {}", error), .slurp()
} .unwrap_or_else(|error| die!("Error reading justfile: {}", error));
if let Err(error) = env::set_current_dir("..") {
die!("Error changing directory: {}", error);
}
} }
let text = fs::File::open("justfile")
.unwrap_or_else(|error| die!("Error opening justfile: {}", error))
.slurp()
.unwrap_or_else(|error| die!("Error reading justfile: {}", error));
let justfile = super::parse(&text).unwrap_or_else(|error| die!("{}", error)); let justfile = super::parse(&text).unwrap_or_else(|error| die!("{}", error));
if matches.is_present("list") { if matches.is_present("list") {