Skip to content

Commit

Permalink
ux: show which command is run to the user (#491)
Browse files Browse the repository at this point in the history
![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?
  • Loading branch information
ruben-arts authored Nov 23, 2023
1 parent ff912a9 commit 526a33d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
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

0 comments on commit 526a33d

Please sign in to comment.