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)]
|
#[command(version, about, long_about = None)]
|
||||||
pub struct Cli {
|
pub struct Cli {
|
||||||
/// Timeout in seconds for HTTP actions
|
/// Timeout in seconds for HTTP actions
|
||||||
#[arg(short, long)]
|
#[arg(short, long, value_name = "SECS")]
|
||||||
pub timeout: Option<u64>,
|
pub timeout: Option<u64>,
|
||||||
|
|
||||||
/// Protocol for Sharry instance
|
/// Protocol for Sharry instance
|
||||||
#[arg(
|
#[arg(
|
||||||
short, long,
|
short, long,
|
||||||
default_value_t = String::from("https"),
|
default_value = "https", value_name = "VARIANT",
|
||||||
value_parser = PossibleValuesParser::new(["http", "https"]),
|
value_parser = PossibleValuesParser::new(["http", "https"])
|
||||||
)]
|
)]
|
||||||
pub proto: String,
|
pub protocol: String,
|
||||||
|
|
||||||
/// Name of the new share
|
/// Name of the new share
|
||||||
#[arg(
|
#[arg(short, long, default_value = "shrupl upload", value_name = "TEXT")]
|
||||||
short, long,
|
|
||||||
default_value_t = String::from("shrupl upload"),
|
|
||||||
)]
|
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
|
||||||
/// Description of the new share
|
/// Description of the new share
|
||||||
#[arg(short, long)]
|
#[arg(short, long, value_name = "TEXT")]
|
||||||
pub desc: Option<String>,
|
pub description: Option<String>,
|
||||||
|
|
||||||
/// Maximum number of views for the new share
|
/// Maximum number of views for the new share
|
||||||
#[arg(short, long, default_value_t = 10)]
|
#[arg(short, long, default_value_t = 10, value_name = "N")]
|
||||||
pub views: u32,
|
pub max_views: u32,
|
||||||
|
|
||||||
/// Chunk size for uploading, in MiB
|
/// Chunk size for uploading, in MiB
|
||||||
#[arg(short, long, default_value_t = 10)]
|
#[arg(short, long, default_value_t = 10, value_name = "N")]
|
||||||
pub chunk: usize,
|
pub chunk_size: usize,
|
||||||
|
|
||||||
/// Base URL for Sharry Instance
|
/// Base URL for Sharry Instance
|
||||||
pub url: String,
|
pub url: String,
|
||||||
|
|
|
||||||
|
|
@ -31,9 +31,9 @@ fn main() {
|
||||||
panic!("NO FILES GIVEN");
|
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();
|
let share = Share::create(&agent, &alias, share).unwrap();
|
||||||
info!("share: {share:?}");
|
info!("share: {share:?}");
|
||||||
|
|
||||||
|
|
@ -41,7 +41,7 @@ fn main() {
|
||||||
let file = file.create(&agent, &share).unwrap();
|
let file = file.create(&agent, &share).unwrap();
|
||||||
info!("file: {file:?}");
|
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());
|
info!("chunk len: {}", chunk.bytes.len());
|
||||||
|
|
||||||
file.upload_chunk(&agent, &alias, &chunk)
|
file.upload_chunk(&agent, &alias, &chunk)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue