Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ux: show which command is run to the user #491

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use rattler_shell::{
shell::ShellEnum,
};
use tokio::task::JoinHandle;
use tracing::Level;

/// Runs task in project.
#[derive(Default, Debug)]
Expand Down Expand Up @@ -137,7 +138,7 @@ pub fn order_tasks(
Ok(s2)
}

pub async fn create_script(task: Task, args: Vec<String>) -> miette::Result<SequentialList> {
pub async fn create_script(task: &Task, args: Vec<String>) -> miette::Result<SequentialList> {
// Construct the script from the task
let task = task
.as_single_command()
Expand Down Expand Up @@ -209,15 +210,31 @@ 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
// NOTE: one CTRL+C is registered it will always stay registered for the rest of the runtime of the program
// 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
Expand Down
2 changes: 1 addition & 1 deletion tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down