use crate::args::Args;12/// Trait for preparing a subcommand to be run.3pub trait Prepare {4/// A method that returns a list of [`PreparedCommand`]s to be run for a given shell and flags.5///6/// # Example7///8/// ```9/// # use crate::{args::Args, Prepare, PreparedCommand};10/// # use argh::FromArgs;11/// # use xshell::Shell;12/// #13/// #[derive(FromArgs)]14/// #[argh(subcommand, name = "check")]15/// struct CheckCommand {}16///17/// impl Prepare for CheckCommand {18/// fn prepare<'a>(&self, sh: &'a Shell, args: Args) -> Vec<PreparedCommand<'a>> {19/// vec![PreparedCommand::new::<Self>(20/// cmd!(sh, "cargo check --workspace"),21/// "Please fix linter errors",22/// )]23/// }24/// }25/// ```26fn prepare<'a>(&self, sh: &'a xshell::Shell, args: Args) -> Vec<PreparedCommand<'a>>;27}2829/// A command with associated metadata, created from a command that implements [`Prepare`].30#[derive(Debug)]31pub struct PreparedCommand<'a> {32/// The name of the command.33pub name: &'static str,3435/// The command to execute36pub command: xshell::Cmd<'a>,3738/// The message to display if the test command fails39pub failure_message: &'static str,4041/// The subdirectory path to run the test command within42pub subdir: Option<&'static str>,4344/// Environment variables that need to be set before the test runs45pub env_vars: Vec<(&'static str, &'static str)>,46}4748impl<'a> PreparedCommand<'a> {49/// Creates a new [`PreparedCommand`] from a [`Cmd`] and a failure message.50///51/// The other fields of [`PreparedCommand`] are filled in with their default values.52///53/// For more information about creating a [`Cmd`], please see the [`cmd!`](xshell::cmd) macro.54///55/// [`Cmd`]: xshell::Cmd56pub fn new<T: argh::SubCommand>(57command: xshell::Cmd<'a>,58failure_message: &'static str,59) -> Self {60Self {61command,62name: T::COMMAND.name,63failure_message,64subdir: None,65env_vars: vec![],66}67}6869/// A builder that overwrites the current sub-directory with a new value.70pub fn with_subdir(mut self, subdir: &'static str) -> Self {71self.subdir = Some(subdir);72self73}7475/// A builder that adds a new environmental variable to the list.76pub fn with_env_var(mut self, key: &'static str, value: &'static str) -> Self {77self.env_vars.push((key, value));78self79}80}818283