shrupl/src/cli.rs
2025-05-28 12:35:35 +00:00

57 lines
1.6 KiB
Rust

use std::time::Duration;
use clap::{Parser, builder::PossibleValuesParser};
use super::sharry::File;
#[derive(Parser, Debug, Hash)]
#[command(version, about, long_about = None)]
pub struct Cli {
/// Timeout in seconds for HTTP actions
#[arg(short, long, value_name = "SECS", value_parser = parse_seconds)]
pub timeout: Option<Duration>,
/// Protocol for Sharry instance
#[arg(
short, long,
default_value = "https", value_name = "VARIANT",
value_parser = PossibleValuesParser::new(["http", "https"])
)]
pub protocol: String,
/// Name of the new share
#[arg(short, long, default_value = "ShrUpl Upload", value_name = "TEXT")]
pub name: String,
/// Description of the new share
#[arg(short, long, value_name = "TEXT")]
pub description: Option<String>,
/// Maximum number of views for the new share
#[arg(short, long, default_value_t = 100, value_name = "N")]
pub max_views: u32,
/// Chunk size for uploading, in MiB
#[arg(short, long, default_value_t = 10, value_name = "N")]
pub chunk_size: usize,
/// Base URL for Sharry Instance
pub url: String,
/// ID of a public alias to use
pub alias: String,
/// Files to upload to the new share
#[arg(value_name = "FILE", required = true, value_parser = parse_sharry_file)]
pub files: Vec<File>,
}
fn parse_seconds(data: &str) -> Result<Duration, String> {
data.parse()
.map(Duration::from_secs)
.map_err(|e| e.to_string())
}
fn parse_sharry_file(data: &str) -> Result<File, String> {
File::new(data).map_err(|e| e.to_string())
}