From 526a33d8655b439e3c263a0829dc43efeecbcc40 Mon Sep 17 00:00:00 2001 From: Ruben Arts Date: Thu, 23 Nov 2023 13:42:36 +0100 Subject: [PATCH] ux: show which command is run to the user (#491) ![image](https://github.com/prefix-dev/pixi/assets/12893423/09887ec9-61d7-4b49-8438-002d987d20da) I think this is enough info, can be less can be more, what do you think? --- src/cli/run.rs | 23 ++++++++++++++++++++--- tests/common/mod.rs | 2 +- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/cli/run.rs b/src/cli/run.rs index de729f40a..9b9b48565 100644 --- a/src/cli/run.rs +++ b/src/cli/run.rs @@ -20,6 +20,7 @@ use rattler_shell::{ shell::ShellEnum, }; use tokio::task::JoinHandle; +use tracing::Level; /// Runs task in project. #[derive(Default, Debug)] @@ -137,7 +138,7 @@ pub fn order_tasks( Ok(s2) } -pub async fn create_script(task: Task, args: Vec) -> miette::Result { +pub async fn create_script(task: &Task, args: Vec) -> miette::Result { // Construct the script from the task let task = task .as_single_command() @@ -209,7 +210,7 @@ pub async fn execute(args: Args) -> miette::Result<()> { let command_env = get_task_env(&project, args.locked, args.frozen).await?; // Execute the commands in the correct order - while let Some((command, args)) = ordered_commands.pop_back() { + while let Some((command, arguments)) = ordered_commands.pop_back() { let cwd = select_cwd(command.working_directory(), &project)?; // Ignore CTRL+C // Specifically so that the child is responsible for its own signal handling @@ -217,7 +218,23 @@ pub async fn execute(args: Args) -> miette::Result<()> { // which is fine when using run in isolation, however if we start to use run in conjunction with // some other command we might want to revaluate this. let ctrl_c = tokio::spawn(async { while tokio::signal::ctrl_c().await.is_ok() {} }); - let script = create_script(command, args).await?; + let script = create_script(&command, arguments).await?; + + // Showing which command is being run if the level allows it. (default should be yes) + if tracing::enabled!(Level::WARN) { + eprintln!( + "{}{}", + console::style("✨ Pixi running: ").bold(), + console::style( + &command + .as_single_command() + .expect("The command should already be parsed") + ) + .blue() + .bold() + ); + } + let status_code = tokio::select! { code = execute_script(script, &command_env, &cwd) => code?, // This should never exit diff --git a/tests/common/mod.rs b/tests/common/mod.rs index a9801f9de..b4ca10597 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -189,7 +189,7 @@ impl PixiControl { let mut result = RunOutput::default(); while let Some((command, args)) = tasks.pop_back() { let cwd = run::select_cwd(command.working_directory(), &project)?; - let script = create_script(command, args).await; + let script = create_script(&command, args).await; if let Ok(script) = script { let output = execute_script_with_output(script, cwd.as_path(), &task_env, None).await;