CLI ergonomy

This commit is contained in:
Jörn-Michael Miehe 2025-06-13 23:50:42 +00:00
parent 5b018cf84b
commit e257d1cf8c
3 changed files with 41 additions and 14 deletions

View file

@ -72,8 +72,8 @@ impl AppState {
.with_style(
ProgressStyle::with_template(&format!(
concat!(
"{{msg:.yellow}}: {{bar:50.cyan/blue}} ",
"{{binary_bytes:.magenta}}{}{{binary_total_bytes:.magenta}} ",
"{{bar:50.cyan/blue}} {{msg:.magenta}}: ",
"{{binary_bytes:.yellow}}{}{{binary_total_bytes:.yellow}} ",
"({{eta}})",
),
style("/").magenta(),

View file

@ -108,7 +108,8 @@ impl CacheFile {
let endpoint = self
.uri
.endpoint(format!("alias/upload/{}/files/tus", self.share_id));
Some(state.start_upload(http, &endpoint, &self.alias_id).unwrap()) // HACK unwrap, somehow retry
// TODO somehow retry
Some(state.start_upload(http, &endpoint, &self.alias_id).unwrap()) // HACK unwrap
} else {
None
}

View file

@ -14,13 +14,39 @@ use std::{
use clap::Parser;
use console::style;
use dialoguer::{Confirm, theme::ColorfulTheme};
use dialoguer::{Select, theme::ColorfulTheme};
use log::{error, info, trace};
use appstate::AppState;
use cli::Cli;
use sharry::ClientError;
fn prompt_continue() -> bool {
let prompt = format!(
"This operation has previously been stopped. {}",
style("How to proceed?").cyan()
);
let choices = [
format!("Load and {}", style("continue operation").green().bold()),
format!("Start a {}", style("new operation").cyan().bold()),
format!("Quit {}", style("ShrUpl").yellow().bold()),
];
let selection = Select::with_theme(&ColorfulTheme::default())
.with_prompt(prompt)
.default(0)
.items(&choices)
.interact()
.unwrap_or(2);
if selection == 2 {
process::exit(255);
}
selection == 0
}
fn print_error(e: &ClientError) {
if let Some(cause) = match e {
// known errors
@ -77,13 +103,7 @@ fn main() {
info!("args: {args:?}");
let mut state = AppState::try_resume(&args)
.and_then(|state| {
Confirm::with_theme(&ColorfulTheme::default())
.with_prompt("Continue previously stopped operation?")
.default(true)
.interact()
.map_or(None, |b| b.then_some(state))
})
.and_then(|state| prompt_continue().then_some(state))
.unwrap_or_else(|| {
check_ctrlc();
@ -107,10 +127,16 @@ fn main() {
info!("continuing with state: {state:?}");
let fns_magenta = state
.file_names()
.iter()
.map(|&n| style(n).magenta().to_string())
.collect::<Vec<_>>()
.join(", ");
println!(
"{} uploading: {}",
"{} is uploading: {fns_magenta}",
style("ShrUpl").yellow().bold(),
style(state.file_names().join(", ")).magenta(),
);
let mut buffer = vec![0; args.chunk_size * 1024 * 1024];
@ -118,7 +144,7 @@ fn main() {
loop {
match state.upload_chunk(&mut buffer) {
Err(e) => {
// HACK handle errors better (this will just retry endlessly)
// TODO better error handling (this will just retry endlessly)
error!("error: {e:?}");
if let Some(s) = state.rewind() {