Add --show command line flag
This commit is contained in:
parent
fa3856669f
commit
2ab75ef03a
3
notes
3
notes
@ -1,6 +1,8 @@
|
||||
notes
|
||||
-----
|
||||
|
||||
- fix --show to not print final newline, add a helper that iterates over
|
||||
(item, first, last)
|
||||
- look through all justfiles for features of make that I use. so far:
|
||||
. phony
|
||||
. SHELL := zsh
|
||||
@ -11,7 +13,6 @@ notes
|
||||
|
||||
command line arguments:
|
||||
- --show recipe: print recipe information
|
||||
- --list recipes if a bad recipe given
|
||||
|
||||
execution:
|
||||
- indent for line continuation
|
||||
|
16
src/lib.rs
16
src/lib.rs
@ -41,7 +41,7 @@ fn re(pattern: &str) -> Regex {
|
||||
Regex::new(pattern).unwrap()
|
||||
}
|
||||
|
||||
struct Recipe<'a> {
|
||||
pub struct Recipe<'a> {
|
||||
line: usize,
|
||||
name: &'a str,
|
||||
leading_whitespace: &'a str,
|
||||
@ -49,6 +49,16 @@ struct Recipe<'a> {
|
||||
dependencies: BTreeSet<&'a str>,
|
||||
}
|
||||
|
||||
impl<'a> Display for Recipe<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
try!(writeln!(f, "{}:", self.name));
|
||||
for command in self.commands.iter() {
|
||||
try!(writeln!(f, " {}", command));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn error_from_signal<'a>(recipe: &'a str, exit_status: process::ExitStatus) -> RunError<'a> {
|
||||
use std::os::unix::process::ExitStatusExt;
|
||||
@ -300,6 +310,10 @@ impl<'a> Justfile<'a> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get(&self, name: &str) -> Option<&Recipe<'a>> {
|
||||
self.recipes.get(name)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
15
src/main.rs
15
src/main.rs
@ -29,6 +29,11 @@ fn main() {
|
||||
.short("l")
|
||||
.long("list")
|
||||
.help("Lists available recipes"))
|
||||
.arg(Arg::with_name("show")
|
||||
.short("s")
|
||||
.long("show")
|
||||
.takes_value(true)
|
||||
.help("Show information about a recipe"))
|
||||
.arg(Arg::with_name("recipe")
|
||||
.multiple(true)
|
||||
.help("recipe(s) to run, defaults to the first recipe in the justfile"))
|
||||
@ -70,6 +75,16 @@ fn main() {
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
if let Some(name) = matches.value_of("show") {
|
||||
match justfile.get(name) {
|
||||
Some(recipe) => {
|
||||
warn!("{}", recipe);
|
||||
std::process::exit(0);
|
||||
}
|
||||
None => die!("justfile contains no recipe \"{}\"", name)
|
||||
}
|
||||
}
|
||||
|
||||
let names = if let Some(names) = matches.values_of("recipe") {
|
||||
names.collect::<Vec<_>>()
|
||||
} else if let Some(name) = justfile.first() {
|
||||
|
Loading…
Reference in New Issue
Block a user