#[doc(hidden)]
pub use laravel_console::console::__Registration;
pub(crate) use laravel_console::console::*;
#[doc(inline)]
pub use laravel_console::console::{
Choice, ChoicePrompt, Command, CommandResult, Commands, Console, MultiselectPrompt, PasswordPrompt, Progress,
ProgressGroup, ProgressUpdate, Prompt, PromptError, Shutdown, Signal, Signals, Suggest, Verbosity, clap, command,
commands, escape_markup,
};
#[cfg(test)]
mod tests {
use super::*;
use crate::Result;
use crate::foundation::StartupError;
use crate::testing::MakesConsoleRequests;
#[command("discovered:probe")]
async fn probe(console: &mut Console) -> Result<()> {
console.line("discovered");
Ok(())
}
#[derive(clap::Parser)]
#[command(name = "discovered:probe")]
struct Replacement;
#[command]
impl Replacement {
async fn handle(self, console: &mut Console) -> Result<()> {
console.line("application");
Ok(())
}
}
inventory::submit! {
__Registration {
crate_name: "app",
name: || "app::probe",
definition: || <probe as clap::CommandFactory>::command(),
register: |commands| { commands.add::<probe>(); },
}
}
#[tokio::test]
async fn app_commands_are_discovered_before_application_callbacks() {
let discovered = crate::Application::configure()
.replace_env(crate::config::Env::default())
.create();
discovered
.command("discovered:probe")
.await
.assert_successful()
.assert_output_contains("discovered");
let replaced = crate::Application::configure()
.replace_env(crate::config::Env::default())
.with_commands(|commands, _| {
commands.add::<Replacement>();
})
.create();
replaced
.command("discovered:probe")
.await
.assert_successful()
.assert_output_contains("application");
}
inventory::submit! {
__Registration {
crate_name: "conflicting_package",
name: || "conflicting_package::first",
definition: || <probe as clap::CommandFactory>::command(),
register: |commands| { commands.add::<probe>(); },
}
}
inventory::submit! {
__Registration {
crate_name: "conflicting_package",
name: || "conflicting_package::second",
definition: || <Replacement as clap::CommandFactory>::command(),
register: |commands| { commands.add::<Replacement>(); },
}
}
#[test]
fn two_discovered_commands_with_one_name_stop_the_application() {
let error = crate::Application::configure()
.replace_env(crate::config::Env::default())
.with_commands(|commands, _| {
commands.discover("conflicting_package").discover("conflicting_package");
})
.try_create()
.unwrap_err();
assert_eq!(
error,
StartupError::Commands(
"command `discovered:probe` is registered by both `conflicting_package::first` and `conflicting_package::second`"
.to_owned()
)
);
}
}