mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 12:58:54 -05:00
fix(upgrade): respect the --quiet
flag (#16888)
Also, use `ProgressBar` for upgrading.
This commit is contained in:
parent
1615852025
commit
05469fc382
1 changed files with 16 additions and 21 deletions
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
use crate::args::UpgradeFlags;
|
use crate::args::UpgradeFlags;
|
||||||
use crate::colors;
|
use crate::colors;
|
||||||
|
use crate::util::progress_bar::ProgressBar;
|
||||||
use crate::version;
|
use crate::version;
|
||||||
|
|
||||||
use deno_core::anyhow::bail;
|
use deno_core::anyhow::bail;
|
||||||
|
@ -17,7 +18,6 @@ use once_cell::sync::Lazy;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::Write;
|
|
||||||
use std::ops::Sub;
|
use std::ops::Sub;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
@ -281,7 +281,7 @@ pub async fn upgrade(upgrade_flags: UpgradeFlags) -> Result<(), AnyError> {
|
||||||
&& upgrade_flags.output.is_none()
|
&& upgrade_flags.output.is_none()
|
||||||
&& current_is_passed
|
&& current_is_passed
|
||||||
{
|
{
|
||||||
println!("Version {} is already installed", crate::version::deno());
|
log::info!("Version {} is already installed", crate::version::deno());
|
||||||
return Ok(());
|
return Ok(());
|
||||||
} else {
|
} else {
|
||||||
passed_version
|
passed_version
|
||||||
|
@ -289,10 +289,10 @@ pub async fn upgrade(upgrade_flags: UpgradeFlags) -> Result<(), AnyError> {
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let latest_version = if upgrade_flags.canary {
|
let latest_version = if upgrade_flags.canary {
|
||||||
println!("Looking up latest canary version");
|
log::info!("Looking up latest canary version");
|
||||||
get_latest_canary_version(&client).await?
|
get_latest_canary_version(&client).await?
|
||||||
} else {
|
} else {
|
||||||
println!("Looking up latest version");
|
log::info!("Looking up latest version");
|
||||||
get_latest_release_version(&client).await?
|
get_latest_release_version(&client).await?
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -311,13 +311,13 @@ pub async fn upgrade(upgrade_flags: UpgradeFlags) -> Result<(), AnyError> {
|
||||||
&& upgrade_flags.output.is_none()
|
&& upgrade_flags.output.is_none()
|
||||||
&& current_is_most_recent
|
&& current_is_most_recent
|
||||||
{
|
{
|
||||||
println!(
|
log::info!(
|
||||||
"Local deno version {} is the most recent release",
|
"Local deno version {} is the most recent release",
|
||||||
crate::version::deno()
|
crate::version::deno()
|
||||||
);
|
);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
} else {
|
} else {
|
||||||
println!("Found latest version {}", latest_version);
|
log::info!("Found latest version {}", latest_version);
|
||||||
latest_version
|
latest_version
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -341,7 +341,7 @@ pub async fn upgrade(upgrade_flags: UpgradeFlags) -> Result<(), AnyError> {
|
||||||
|
|
||||||
let archive_data = download_package(client, &download_url).await?;
|
let archive_data = download_package(client, &download_url).await?;
|
||||||
|
|
||||||
println!("Deno is upgrading to version {}", &install_version);
|
log::info!("Deno is upgrading to version {}", &install_version);
|
||||||
|
|
||||||
let new_exe_path = unpack(archive_data, cfg!(windows))?;
|
let new_exe_path = unpack(archive_data, cfg!(windows))?;
|
||||||
fs::set_permissions(&new_exe_path, permissions)?;
|
fs::set_permissions(&new_exe_path, permissions)?;
|
||||||
|
@ -357,7 +357,7 @@ pub async fn upgrade(upgrade_flags: UpgradeFlags) -> Result<(), AnyError> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Upgraded successfully");
|
log::info!("Upgraded successfully");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -407,7 +407,7 @@ async fn download_package(
|
||||||
client: Client,
|
client: Client,
|
||||||
download_url: &str,
|
download_url: &str,
|
||||||
) -> Result<Vec<u8>, AnyError> {
|
) -> Result<Vec<u8>, AnyError> {
|
||||||
println!("Checking {}", &download_url);
|
log::info!("Downloading {}", &download_url);
|
||||||
|
|
||||||
let res = client.get(download_url).send().await?;
|
let res = client.get(download_url).send().await?;
|
||||||
|
|
||||||
|
@ -417,32 +417,27 @@ async fn download_package(
|
||||||
let mut data = Vec::with_capacity(total_size as usize);
|
let mut data = Vec::with_capacity(total_size as usize);
|
||||||
let mut stream = res.bytes_stream();
|
let mut stream = res.bytes_stream();
|
||||||
let mut skip_print = 0;
|
let mut skip_print = 0;
|
||||||
let is_tty = atty::is(atty::Stream::Stdout);
|
|
||||||
const MEBIBYTE: f64 = 1024.0 * 1024.0;
|
const MEBIBYTE: f64 = 1024.0 * 1024.0;
|
||||||
|
let progress_bar = ProgressBar::default();
|
||||||
|
let clear_guard = progress_bar.clear_guard();
|
||||||
while let Some(item) = stream.next().await {
|
while let Some(item) = stream.next().await {
|
||||||
let bytes = item?;
|
let bytes = item?;
|
||||||
current_size += bytes.len() as f64;
|
current_size += bytes.len() as f64;
|
||||||
data.extend_from_slice(&bytes);
|
data.extend_from_slice(&bytes);
|
||||||
if skip_print == 0 {
|
if skip_print == 0 {
|
||||||
if is_tty {
|
progress_bar.update(&format!(
|
||||||
print!("\u{001b}[1G\u{001b}[2K");
|
|
||||||
}
|
|
||||||
print!(
|
|
||||||
"{:>4.1} MiB / {:.1} MiB ({:^5.1}%)",
|
"{:>4.1} MiB / {:.1} MiB ({:^5.1}%)",
|
||||||
current_size / MEBIBYTE,
|
current_size / MEBIBYTE,
|
||||||
total_size / MEBIBYTE,
|
total_size / MEBIBYTE,
|
||||||
(current_size / total_size) * 100.0,
|
(current_size / total_size) * 100.0,
|
||||||
);
|
));
|
||||||
std::io::stdout().flush()?;
|
|
||||||
skip_print = 10;
|
skip_print = 10;
|
||||||
} else {
|
} else {
|
||||||
skip_print -= 1;
|
skip_print -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if is_tty {
|
drop(clear_guard);
|
||||||
print!("\u{001b}[1G\u{001b}[2K");
|
log::info!(
|
||||||
}
|
|
||||||
println!(
|
|
||||||
"{:.1} MiB / {:.1} MiB (100.0%)",
|
"{:.1} MiB / {:.1} MiB (100.0%)",
|
||||||
current_size / MEBIBYTE,
|
current_size / MEBIBYTE,
|
||||||
total_size / MEBIBYTE
|
total_size / MEBIBYTE
|
||||||
|
@ -450,7 +445,7 @@ async fn download_package(
|
||||||
|
|
||||||
Ok(data)
|
Ok(data)
|
||||||
} else {
|
} else {
|
||||||
println!("Download could not be found, aborting");
|
log::info!("Download could not be found, aborting");
|
||||||
std::process::exit(1)
|
std::process::exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue