diff --git a/src/parse/matches/arg_matches.rs b/src/parse/matches/arg_matches.rs index edbdb91c9a3..4f4b25b51c2 100644 --- a/src/parse/matches/arg_matches.rs +++ b/src/parse/matches/arg_matches.rs @@ -80,6 +80,29 @@ pub struct ArgMatches { } impl ArgMatches { + /// Check if any args were present on the command line + /// + /// # Examples + /// + /// ```rust + /// # use clap::{App, Arg}; + /// let mut app = App::new("myapp") + /// .arg(Arg::new("output") + /// .takes_value(true)); + /// + /// let m = app + /// .try_get_matches_from_mut(vec!["myapp", "something"]) + /// .unwrap(); + /// assert!(m.args_present()); + /// + /// let m = app + /// .try_get_matches_from_mut(vec!["myapp"]) + /// .unwrap(); + /// assert!(! m.args_present()); + pub fn args_present(&self) -> bool { + !self.args.is_empty() + } + /// Gets the value of a specific option or positional argument. /// /// i.e. an argument that [takes an additional value][crate::Arg::takes_value] at runtime.