CLI ergonomy
This commit is contained in:
parent
5b018cf84b
commit
e257d1cf8c
3 changed files with 41 additions and 14 deletions
|
|
@ -72,8 +72,8 @@ impl AppState {
|
||||||
.with_style(
|
.with_style(
|
||||||
ProgressStyle::with_template(&format!(
|
ProgressStyle::with_template(&format!(
|
||||||
concat!(
|
concat!(
|
||||||
"{{msg:.yellow}}: {{bar:50.cyan/blue}} ",
|
"{{bar:50.cyan/blue}} {{msg:.magenta}}: ",
|
||||||
"{{binary_bytes:.magenta}}{}{{binary_total_bytes:.magenta}} ",
|
"{{binary_bytes:.yellow}}{}{{binary_total_bytes:.yellow}} ",
|
||||||
"({{eta}})",
|
"({{eta}})",
|
||||||
),
|
),
|
||||||
style("/").magenta(),
|
style("/").magenta(),
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,8 @@ impl CacheFile {
|
||||||
let endpoint = self
|
let endpoint = self
|
||||||
.uri
|
.uri
|
||||||
.endpoint(format!("alias/upload/{}/files/tus", self.share_id));
|
.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 {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
||||||
48
src/main.rs
48
src/main.rs
|
|
@ -14,13 +14,39 @@ use std::{
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use console::style;
|
use console::style;
|
||||||
use dialoguer::{Confirm, theme::ColorfulTheme};
|
use dialoguer::{Select, theme::ColorfulTheme};
|
||||||
use log::{error, info, trace};
|
use log::{error, info, trace};
|
||||||
|
|
||||||
use appstate::AppState;
|
use appstate::AppState;
|
||||||
use cli::Cli;
|
use cli::Cli;
|
||||||
use sharry::ClientError;
|
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) {
|
fn print_error(e: &ClientError) {
|
||||||
if let Some(cause) = match e {
|
if let Some(cause) = match e {
|
||||||
// known errors
|
// known errors
|
||||||
|
|
@ -77,13 +103,7 @@ fn main() {
|
||||||
info!("args: {args:?}");
|
info!("args: {args:?}");
|
||||||
|
|
||||||
let mut state = AppState::try_resume(&args)
|
let mut state = AppState::try_resume(&args)
|
||||||
.and_then(|state| {
|
.and_then(|state| prompt_continue().then_some(state))
|
||||||
Confirm::with_theme(&ColorfulTheme::default())
|
|
||||||
.with_prompt("Continue previously stopped operation?")
|
|
||||||
.default(true)
|
|
||||||
.interact()
|
|
||||||
.map_or(None, |b| b.then_some(state))
|
|
||||||
})
|
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
check_ctrlc();
|
check_ctrlc();
|
||||||
|
|
||||||
|
|
@ -107,10 +127,16 @@ fn main() {
|
||||||
|
|
||||||
info!("continuing with state: {state:?}");
|
info!("continuing with state: {state:?}");
|
||||||
|
|
||||||
|
let fns_magenta = state
|
||||||
|
.file_names()
|
||||||
|
.iter()
|
||||||
|
.map(|&n| style(n).magenta().to_string())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(", ");
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"{} uploading: {}",
|
"{} is uploading: {fns_magenta}",
|
||||||
style("ShrUpl").yellow().bold(),
|
style("ShrUpl").yellow().bold(),
|
||||||
style(state.file_names().join(", ")).magenta(),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut buffer = vec![0; args.chunk_size * 1024 * 1024];
|
let mut buffer = vec![0; args.chunk_size * 1024 * 1024];
|
||||||
|
|
@ -118,7 +144,7 @@ fn main() {
|
||||||
loop {
|
loop {
|
||||||
match state.upload_chunk(&mut buffer) {
|
match state.upload_chunk(&mut buffer) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// HACK handle errors better (this will just retry endlessly)
|
// TODO better error handling (this will just retry endlessly)
|
||||||
error!("error: {e:?}");
|
error!("error: {e:?}");
|
||||||
|
|
||||||
if let Some(s) = state.rewind() {
|
if let Some(s) = state.rewind() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue