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::{convert, ffi};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use self::clap::{App, Arg, ArgGroup, AppSettings};
|
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 {
|
macro_rules! warn {
|
||||||
($($arg:tt)*) => {{
|
($($arg:tt)*) => {{
|
||||||
@ -334,7 +334,12 @@ pub fn app() {
|
|||||||
let arguments = if !rest.is_empty() {
|
let arguments = if !rest.is_empty() {
|
||||||
rest
|
rest
|
||||||
} else if let Some(recipe) = justfile.first() {
|
} 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 {
|
} else {
|
||||||
die!("Justfile contains no recipes.");
|
die!("Justfile contains no recipes.");
|
||||||
};
|
};
|
||||||
|
@ -1169,8 +1169,8 @@ struct RunOptions<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b> Justfile<'a> where 'a: 'b {
|
impl<'a, 'b> Justfile<'a> where 'a: 'b {
|
||||||
fn first(&self) -> Option<&'a str> {
|
fn first(&self) -> Option<&Recipe> {
|
||||||
let mut first: Option<&Recipe<'a>> = None;
|
let mut first: Option<&Recipe> = None;
|
||||||
for recipe in self.recipes.values() {
|
for recipe in self.recipes.values() {
|
||||||
if let Some(first_recipe) = first {
|
if let Some(first_recipe) = first {
|
||||||
if recipe.line_number < first_recipe.line_number {
|
if recipe.line_number < first_recipe.line_number {
|
||||||
@ -1180,7 +1180,7 @@ impl<'a, 'b> Justfile<'a> where 'a: 'b {
|
|||||||
first = Some(recipe);
|
first = Some(recipe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
first.map(|recipe| recipe.name)
|
first
|
||||||
}
|
}
|
||||||
|
|
||||||
fn count(&self) -> usize {
|
fn count(&self) -> usize {
|
||||||
|
Loading…
Reference in New Issue
Block a user