Error if running default recipe that requires arguments (#194)
This commit is contained in:
parent
200cb4ee26
commit
616d324cd7
@ -7,7 +7,7 @@ use ::prelude::*;
|
||||
use std::{convert, ffi};
|
||||
use std::collections::BTreeMap;
|
||||
use self::clap::{App, Arg, ArgGroup, AppSettings};
|
||||
use super::{Slurp, RunOptions, compile, DEFAULT_SHELL};
|
||||
use super::{Slurp, RunOptions, compile, DEFAULT_SHELL, maybe_s};
|
||||
|
||||
macro_rules! warn {
|
||||
($($arg:tt)*) => {{
|
||||
@ -334,7 +334,12 @@ pub fn app() {
|
||||
let arguments = if !rest.is_empty() {
|
||||
rest
|
||||
} else if let Some(recipe) = justfile.first() {
|
||||
vec![recipe]
|
||||
let min_arguments = recipe.min_arguments();
|
||||
if min_arguments > 0 {
|
||||
die!("Recipe `{}` cannot be used as default recipe since it requires at least {} argument{}.",
|
||||
recipe.name, min_arguments, maybe_s(min_arguments));
|
||||
}
|
||||
vec![recipe.name]
|
||||
} else {
|
||||
die!("Justfile contains no recipes.");
|
||||
};
|
||||
|
@ -1169,8 +1169,8 @@ struct RunOptions<'a> {
|
||||
}
|
||||
|
||||
impl<'a, 'b> Justfile<'a> where 'a: 'b {
|
||||
fn first(&self) -> Option<&'a str> {
|
||||
let mut first: Option<&Recipe<'a>> = None;
|
||||
fn first(&self) -> Option<&Recipe> {
|
||||
let mut first: Option<&Recipe> = None;
|
||||
for recipe in self.recipes.values() {
|
||||
if let Some(first_recipe) = first {
|
||||
if recipe.line_number < first_recipe.line_number {
|
||||
@ -1180,7 +1180,7 @@ impl<'a, 'b> Justfile<'a> where 'a: 'b {
|
||||
first = Some(recipe);
|
||||
}
|
||||
}
|
||||
first.map(|recipe| recipe.name)
|
||||
first
|
||||
}
|
||||
|
||||
fn count(&self) -> usize {
|
||||
|
Loading…
Reference in New Issue
Block a user