1
1
mirror of https://github.com/casey/just.git synced 2024-11-24 04:38:25 +03:00

Error if running default recipe that requires arguments (#194)

This commit is contained in:
Casey Rodarmor 2017-05-07 15:11:10 -07:00 committed by GitHub
parent 200cb4ee26
commit 616d324cd7
2 changed files with 10 additions and 5 deletions

View File

@ -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.");
};

View File

@ -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 {