Skip to content

Commit

Permalink
Add color to each step of spin build and spin up
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
  • Loading branch information
rylev committed May 22, 2023
1 parent d476000 commit bd66bbf
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions crates/build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,20 @@ pub async fn build(manifest_file: &Path) -> Result<()> {
println!("No build command found!");
return Ok(());
}

app.components
.into_iter()
.map(|c| build_component(c, &app_dir))
.collect::<Result<Vec<_>, _>>()?;

println!("Successfully ran the build command for the Spin components.");
terminal::step!("Finished", "building all Spin components");
Ok(())
}

/// Run the build command of the component.
fn build_component(raw: RawComponentManifest, app_dir: &Path) -> Result<()> {
match raw.build {
Some(b) => {
println!(
"Executing the build command for component {}: {}",
raw.id, b.command
);
terminal::step!("Building", "component {} with `{}`", raw.id, b.command);
let workdir = construct_workdir(app_dir, b.workdir.as_ref())?;
if b.workdir.is_some() {
println!("Working directory: {:?}", workdir);
Expand Down
9 changes: 5 additions & 4 deletions crates/terminal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,21 @@ fn color_choice(stream: atty::Stream) -> termcolor::ColorChoice {

#[macro_export]
macro_rules! step {
($step:expr, $($arg:tt)*) => {
($step:expr, $($arg:tt)*) => {{

$crate::cprint!($crate::colors::bold_green(), $step);
print!(" ");
println!($($arg)*);
};
}};
}

#[macro_export]
macro_rules! error {
($($arg:tt)*) => {
($($arg:tt)*) => {{
$crate::ceprint!($crate::colors::bold_red(), "Error");
eprint!(": ");
eprintln!($($arg)*);
};
}};
}

#[macro_export]
Expand Down
1 change: 1 addition & 0 deletions crates/trigger-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ spin-core = { path = "../core" }
spin-http = { path = "../http" }
spin-trigger = { path = "../trigger" }
spin-world = { path = "../world" }
terminal = { path = "../terminal" }
tls-listener = { version = "0.4.0", features = [
"rustls",
"hyper-h1",
Expand Down
2 changes: 1 addition & 1 deletion crates/trigger-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl TriggerExecutor for HttpTrigger {
// Print startup messages
let scheme = if tls.is_some() { "https" } else { "http" };
let base_url = format!("{}://{:?}", scheme, listen_addr);
println!("\nServing {}", base_url);
terminal::step!("\nServing", "{}", base_url);
log::info!("Serving {}", base_url);

println!("Available Routes:");
Expand Down

0 comments on commit bd66bbf

Please sign in to comment.