Skip to content

Commit

Permalink
spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
overcat committed Aug 29, 2024
1 parent aeff349 commit a3d9359
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
22 changes: 8 additions & 14 deletions cmd/soroban-cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use clap::CommandFactory;
use dotenvy::dotenv;
use std::thread;
use tracing_subscriber::{fmt, EnvFilter};

use crate::self_outdated_check::print_upgrade_prompt;
use crate::{commands, Root};

#[tokio::main]
pub async fn main() {
// Spawn a thread to print the upgrade prompt in the background
thread::spawn(print_upgrade_prompt);

let _ = dotenv().unwrap_or_default();

// Map SOROBAN_ env vars to STELLAR_ env vars for backwards compatibility
Expand Down Expand Up @@ -35,16 +39,13 @@ pub async fn main() {
let mut root = Root::new().unwrap_or_else(|e| match e {
commands::Error::Clap(e) => {
let mut cmd = Root::command();
let e = e.format(&mut cmd);
let _ = e.print();
exit(e.exit_code());
e.format(&mut cmd).exit();
}
e => {
eprintln!("{e}");
exit(1);
std::process::exit(1);
}
});

// Now use root to setup the logger
if let Some(level) = root.global_args.log_level() {
let mut e_filter = EnvFilter::from_default_env()
Expand All @@ -58,7 +59,7 @@ pub async fn main() {
.parse()
.map_err(|e| {
eprintln!("{e}: {filter}");
exit(1);
std::process::exit(1);
})
.unwrap(),
);
Expand All @@ -76,13 +77,6 @@ pub async fn main() {

if let Err(e) = root.run().await {
eprintln!("error: {e}");
exit(1);
std::process::exit(1);
}

print_upgrade_prompt(root.global_args.quiet);
}

fn exit(exit_code: i32) -> ! {
print_upgrade_prompt(false);
std::process::exit(exit_code);
}
5 changes: 2 additions & 3 deletions cmd/soroban-cli/src/self_outdated_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn fetch_latest_crate_info() -> Result<Crate, Box<dyn Error>> {
}

/// Print a warning if a new version of the CLI is available
pub fn print_upgrade_prompt(quiet: bool) {
pub fn print_upgrade_prompt() {
// We should skip the upgrade check if we're not in a tty environment.
if !std::io::stderr().is_terminal() {
return;
Expand All @@ -48,7 +48,7 @@ pub fn print_upgrade_prompt(quiet: bool) {
}

let current_version = crate::commands::version::pkg();
let print = Print::new(quiet);
let print = Print::new(false);

let mut stats = SelfOutdatedCheck::load().unwrap_or_default();

Expand All @@ -71,7 +71,6 @@ pub fn print_upgrade_prompt(quiet: bool) {
let latest_version = get_latest_version(&current_version, &stats);

if latest_version > current_version {
print.println("");
print.warnln(format!(
"A new release of stellar-cli is available: {current_version} -> {latest_version}",
));
Expand Down

0 comments on commit a3d9359

Please sign in to comment.