From 616d324cd76d81bb1bb3abc5ce9212f1877b463c Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sun, 7 May 2017 15:11:10 -0700 Subject: [PATCH] Error if running default recipe that requires arguments (#194) --- src/app.rs | 9 +++++++-- src/lib.rs | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/app.rs b/src/app.rs index 594f8b3..3d6d7da 100644 --- a/src/app.rs +++ b/src/app.rs @@ -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."); }; diff --git a/src/lib.rs b/src/lib.rs index 4d61d96..2b2acb0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 {