Skip to content

Commit

Permalink
prettyprint
Browse files Browse the repository at this point in the history
  • Loading branch information
mwrites committed Apr 25, 2023
1 parent 211ea9b commit 547c51e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 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.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ spl-memo = "3.0.1"
spl-token = "~3.5.0"
tar = "0.4"
thiserror = "1.0.30"
termcolor = "1.2.0"

[[bin]]
name = "clockwork"
Expand Down
22 changes: 10 additions & 12 deletions cli/src/deps.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use {
crate::config::{
self,
CliConfig,
},
super::*,
anyhow::{
Context,
Result,
Expand Down Expand Up @@ -76,21 +73,23 @@ pub fn download_and_extract(
force_init: bool,
) -> Result<()> {
if !force_init && all_target_files_exist(runtime_dir, files_to_extract) {
println!("Files {:#?} already exist", files_to_extract);
print_note!("Using {:#?} from cache", files_to_extract.join(", "));
return Ok(());
}
// create runtime dir if necessary
fs::create_dir_all(runtime_dir)
.context(format!("Unable to create dirs for {:#?}", runtime_dir))?;
download_file(src_url, &dest_path)?;
extract_archive(&dest_path, runtime_dir, files_to_extract)
extract_archive(&dest_path, runtime_dir, files_to_extract)?;
println!();
Ok(())
}
fn download_file(url: &str, dest: &Path) -> Result<()> {
// Check if the input is a URL or a local path
match Url::parse(url) {
Ok(url) => {
// Download the file from the internet
println!("Downloading {}", url);
print_status!("Downloading", "{}", &url.to_string());
let response =
get(url.clone()).context(format!("Failed to download file from {}", url))?;
if response.status() != reqwest::StatusCode::OK {
Expand All @@ -99,7 +98,7 @@ fn download_file(url: &str, dest: &Path) -> Result<()> {

let pb = ProgressBar::new(response.content_length().unwrap_or(0));
pb.set_style(ProgressStyle::default_bar()
.template("{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {bytes}/{total_bytes} ({eta})")
.template("{spinner:.green} 🚚 [{elapsed_precise}] [{bar:40.cyan/blue}] {bytes}/{total_bytes} ({eta})")
.progress_chars("#>-"));

let mut source = pb.wrap_read(response);
Expand All @@ -125,11 +124,10 @@ fn extract_archive(
) -> Result<()> {
let file =
File::open(&archive_path).context(format!("Failed to open file {:#?}", archive_path))?;
let mut archive = Archive::new(BzDecoder::new(file));

let target_file_names: Vec<&OsStr> = files_to_extract.iter().map(OsStr::new).collect();
let mut archive = Archive::new(BzDecoder::new(file));

println!("📦 Extracting...");
print_status!("Extracting", "{:?}", archive_path);
archive
.entries()?
.filter_map(|e| e.ok())
Expand Down Expand Up @@ -158,7 +156,7 @@ fn extract_archive(
})
.filter_map(|e| e.ok())
.for_each(|x| {
println!("> {}", x.display());
print_status!(">", "{}", x.display());
});
Ok(())
}
Expand Down
7 changes: 6 additions & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ mod config;
mod deps;
mod errors;
mod parser;
mod print;
mod processor;

use {
crate::{
config::CliConfig,
print::print_style,
},
cli::app,
errors::CliError,
processor::process,
};

fn main() -> Result<(), CliError> {
process(&app().get_matches()).map_err(|e| {
eprintln!("{}", e);
print_error!("{}", e);
e
})
}
9 changes: 7 additions & 2 deletions cli/src/processor/localnet.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
use {
crate::print_status,
clap::crate_version,
};
#[allow(deprecated)]
use {
crate::{
config::CliConfig,
deps,
errors::CliError,
parser::ProgramInfo,
print::print_style,
},
anyhow::{
Context,
Expand Down Expand Up @@ -251,7 +256,7 @@ fn start_test_validator(
network_url: Option<String>,
clone_addresses: Vec<Pubkey>,
) -> Result<Child> {
println!("Starting test validator");
print_status!("Running", "Clockwork Validator {}\n", crate_version!());

let path = config.active_runtime("solana-test-validator").to_owned();
let cmd = &mut Command::new(path);
Expand All @@ -266,7 +271,7 @@ fn start_test_validator(

let mut process = cmd
.spawn()
.context(format!("olana-test-validator command: {:#?}", cmd))?;
.context(format!("solana-test-validator command: {:#?}", cmd))?;

// Wait for the validator to become healthy
let ms_wait = 10_000;
Expand Down

0 comments on commit 547c51e

Please sign in to comment.