CLI ergonomy
This commit is contained in:
parent
fdccab81fa
commit
2dab3c9ecd
2 changed files with 14 additions and 17 deletions
25
src/cli.rs
25
src/cli.rs
|
|
@ -6,35 +6,32 @@ use clap::{Parser, builder::PossibleValuesParser};
|
|||
#[command(version, about, long_about = None)]
|
||||
pub struct Cli {
|
||||
/// Timeout in seconds for HTTP actions
|
||||
#[arg(short, long)]
|
||||
#[arg(short, long, value_name = "SECS")]
|
||||
pub timeout: Option<u64>,
|
||||
|
||||
/// Protocol for Sharry instance
|
||||
#[arg(
|
||||
short, long,
|
||||
default_value_t = String::from("https"),
|
||||
value_parser = PossibleValuesParser::new(["http", "https"]),
|
||||
default_value = "https", value_name = "VARIANT",
|
||||
value_parser = PossibleValuesParser::new(["http", "https"])
|
||||
)]
|
||||
pub proto: String,
|
||||
pub protocol: String,
|
||||
|
||||
/// Name of the new share
|
||||
#[arg(
|
||||
short, long,
|
||||
default_value_t = String::from("shrupl upload"),
|
||||
)]
|
||||
#[arg(short, long, default_value = "shrupl upload", value_name = "TEXT")]
|
||||
pub name: String,
|
||||
|
||||
/// Description of the new share
|
||||
#[arg(short, long)]
|
||||
pub desc: Option<String>,
|
||||
#[arg(short, long, value_name = "TEXT")]
|
||||
pub description: Option<String>,
|
||||
|
||||
/// Maximum number of views for the new share
|
||||
#[arg(short, long, default_value_t = 10)]
|
||||
pub views: u32,
|
||||
#[arg(short, long, default_value_t = 10, value_name = "N")]
|
||||
pub max_views: u32,
|
||||
|
||||
/// Chunk size for uploading, in MiB
|
||||
#[arg(short, long, default_value_t = 10)]
|
||||
pub chunk: usize,
|
||||
#[arg(short, long, default_value_t = 10, value_name = "N")]
|
||||
pub chunk_size: usize,
|
||||
|
||||
/// Base URL for Sharry Instance
|
||||
pub url: String,
|
||||
|
|
|
|||
|
|
@ -31,9 +31,9 @@ fn main() {
|
|||
panic!("NO FILES GIVEN");
|
||||
}
|
||||
|
||||
let alias = Alias::new(Uri::with_protocol(args.proto, args.url), args.alias);
|
||||
let alias = Alias::new(Uri::with_protocol(args.protocol, args.url), args.alias);
|
||||
|
||||
let share = NewShareRequest::new(args.name, args.desc, args.views);
|
||||
let share = NewShareRequest::new(args.name, args.description, args.max_views);
|
||||
let share = Share::create(&agent, &alias, share).unwrap();
|
||||
info!("share: {share:?}");
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ fn main() {
|
|||
let file = file.create(&agent, &share).unwrap();
|
||||
info!("file: {file:?}");
|
||||
|
||||
for chunk in file.chunked(args.chunk * 1024 * 1024) {
|
||||
for chunk in file.chunked(args.chunk_size * 1024 * 1024) {
|
||||
info!("chunk len: {}", chunk.bytes.len());
|
||||
|
||||
file.upload_chunk(&agent, &alias, &chunk)
|
||||
|
|
|
|||
Loading…
Reference in a new issue