Skip to content

Commit

Permalink
chore(cli): ux improvements after upload completes
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandSherwin committed Dec 11, 2023
1 parent e1a69e4 commit 6d5d8c1
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions sn_cli/src/subcommands/files/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ async fn upload_files(
}
progress_bar.finish_and_clear();

let elapsed = format_elapsed_time(now.elapsed());
// report errors
let failed_uploads = chunk_manager.get_chunks();
let failed_uploads_len = failed_uploads.len();
Expand All @@ -279,12 +280,14 @@ async fn upload_files(
println!("Failed to upload {failed_uploads_len} chunks with:");
println!("{recorded_upload_errors:#?}");
}
println!("Upload took {elapsed}");
info!("Upload took {elapsed}");
} else {
println!("Uploaded {chunks_to_upload_len} chunks in {elapsed}");
info!("Uploaded {chunks_to_upload_len} chunks in {elapsed}");
}

// log costs
let elapsed = format_elapsed_time(now.elapsed());
println!("Uploaded {chunks_to_upload_len} chunks in {elapsed}");
info!("Uploaded {chunks_to_upload_len} chunks in {elapsed}");
println!("**************************************");
println!("* Payment Details *");
println!("**************************************");
Expand All @@ -295,27 +298,30 @@ async fn upload_files(
info!("New wallet balance: {final_balance}");

// log uploaded file information
println!("**************************************");
println!("* Uploaded Files *");
println!("**************************************");
let file_names_path = root_dir.join("uploaded_files");
let mut file = std::fs::OpenOptions::new()
.create(true)
.write(true)
.append(true)
.open(file_names_path)?;
for (file_name, addr) in chunk_manager.verified_files() {
if let Some(file_name) = file_name.to_str() {
println!("\"{file_name}\" {addr:x}");
info!("Uploaded {file_name} to {addr:x}");
writeln!(file, "{addr:x}: {file_name}")?;
} else {
println!("\"{file_name:?}\" {addr:x}");
info!("Uploaded {file_name:?} to {addr:x}");
writeln!(file, "{addr:x}: {file_name:?}")?;
let verified_files = chunk_manager.verified_files();
if !verified_files.is_empty() {
println!("**************************************");
println!("* Uploaded Files *");
println!("**************************************");
let file_names_path = root_dir.join("uploaded_files");
let mut file = std::fs::OpenOptions::new()
.create(true)
.write(true)
.append(true)
.open(file_names_path)?;
for (file_name, addr) in verified_files {
if let Some(file_name) = file_name.to_str() {
println!("\"{file_name}\" {addr:x}");
info!("Uploaded {file_name} to {addr:x}");
writeln!(file, "{addr:x}: {file_name}")?;
} else {
println!("\"{file_name:?}\" {addr:x}");
info!("Uploaded {file_name:?} to {addr:x}");
writeln!(file, "{addr:x}: {file_name:?}")?;
}
}
file.flush()?;
}
file.flush()?;

Ok(())
}
Expand Down

0 comments on commit 6d5d8c1

Please sign in to comment.