Skip to content

Commit

Permalink
Fix print issue with reporter (#90)
Browse files Browse the repository at this point in the history
* fix: Improve reporting in the format function by using `reporter.emit()` when the reporter guard is held.

Signed-off-by: jaudiger <jeremy.audiger@ioterop.com>

* fix: move the reporter guard in publish function to ensure the lines printed are not affected by the reporter.

Signed-off-by: jaudiger <jeremy.audiger@ioterop.com>

* refactor: rewrite the check of the result when publishing a project in order to remove a return statement.

Signed-off-by: jaudiger <jeremy.audiger@ioterop.com>

---------

Signed-off-by: jaudiger <jeremy.audiger@ioterop.com>
  • Loading branch information
jaudiger authored Jul 17, 2024
1 parent c4e1593 commit ee2479c
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 53 deletions.
69 changes: 42 additions & 27 deletions crates/brioche/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ pub async fn format(args: FormatArgs) -> anyhow::Result<ExitCode> {
for project_path in args.project {
match project_format(&reporter, &project_path, args.check).await {
Err(err) => {
println!(
"Error occurred while formatting project '{project_path}': {err}",
project_path = project_path.display(),
err = err
);
reporter.emit(superconsole::Lines::from_multiline_string(
&format!(
"Error occurred while formatting project '{project_path}': {err}",
project_path = project_path.display(),
err = err
),
superconsole::style::ContentStyle {
foreground_color: Some(superconsole::style::Color::Red),
..superconsole::style::ContentStyle::default()
},
));

error_result = Some(());
}
Expand Down Expand Up @@ -81,35 +87,44 @@ async fn project_format(

if !check {
if !files.is_empty() {
println!(
"The following files of project '{project_path}' have been formatted:\n{files}",
project_path = project_path.display(),
files = files
.iter()
.map(|file| format!("- {}", file.display()))
.collect::<Vec<_>>()
.join("\n")
);
reporter.emit(superconsole::Lines::from_multiline_string(
&format!(
"The following files of project '{project_path}' have been formatted:\n{files}",
project_path = project_path.display(),
files = files
.iter()
.map(|file| format!("- {}", file.display()))
.collect::<Vec<_>>()
.join("\n")
),
superconsole::style::ContentStyle::default(),
));
}

Ok(true)
} else if files.is_empty() {
println!(
"All files of project '{project_path}' are formatted",
project_path = project_path.display()
);
reporter.emit(superconsole::Lines::from_multiline_string(
&format!(
"All files of project '{project_path}' are formatted",
project_path = project_path.display()
),
superconsole::style::ContentStyle::default(),
));

Ok(true)
} else {
println!(
"The following files of project '{project_path}' are not formatted:\n{files}",
project_path = project_path.display(),
files = files
.iter()
.map(|file| format!("- {}", file.display()))
.collect::<Vec<_>>()
.join("\n")
);
reporter.emit(superconsole::Lines::from_multiline_string(
&format!(
"The following files of project '{project_path}' are not formatted:\n{files}",
project_path = project_path.display(),
files = files
.iter()
.map(|file| format!("- {}", file.display()))
.collect::<Vec<_>>()
.join("\n")
),
superconsole::style::ContentStyle::default(),
));

Ok(false)
}
Expand Down
54 changes: 28 additions & 26 deletions crates/brioche/src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,39 @@ pub async fn publish(args: PublishArgs) -> anyhow::Result<ExitCode> {
}

let checked = brioche_core::script::check::check(&brioche, &projects, project_hash).await?;

guard.shutdown_console().await;

let check_results = checked.ensure_ok(brioche_core::script::check::DiagnosticLevel::Warning);
match check_results {
Ok(match check_results {
Ok(()) => {
println!("No errors found 🎉");
}
Err(diagnostics) => {
diagnostics.write(&brioche.vfs, &mut std::io::stdout())?;
return Ok(ExitCode::FAILURE);
}
}

guard.shutdown_console().await;

let response =
brioche_core::publish::publish_project(&brioche, &projects, project_hash, true).await?;
let response =
brioche_core::publish::publish_project(&brioche, &projects, project_hash, true)
.await?;

if response.tags.is_empty() {
println!("Project already up to date: {} {}", name, version);
} else {
println!("🚀 Published project {} {}", name, version);
println!();
println!("Updated tags:");
for tag in &response.tags {
let status = if tag.previous_hash.is_some() {
"updated"
if response.tags.is_empty() {
println!("Project already up to date: {} {}", name, version);
} else {
"new"
};
println!(" {} {} ({status})", tag.name, tag.tag);
}
}
println!("🚀 Published project {} {}", name, version);
println!();
println!("Updated tags:");
for tag in &response.tags {
let status = if tag.previous_hash.is_some() {
"updated"
} else {
"new"
};
println!(" {} {} ({status})", tag.name, tag.tag);
}
}

Ok(ExitCode::SUCCESS)
ExitCode::SUCCESS
}
Err(diagnostics) => {
diagnostics.write(&brioche.vfs, &mut std::io::stdout())?;
ExitCode::FAILURE
}
})
}

0 comments on commit ee2479c

Please sign in to comment.