2025-05-28 12:35:35 +00:00
|
|
|
use std::time::Duration;
|
2025-05-28 00:07:59 +00:00
|
|
|
|
|
|
|
|
use clap::{Parser, builder::PossibleValuesParser};
|
|
|
|
|
|
2025-05-28 12:35:35 +00:00
|
|
|
use super::sharry::File;
|
|
|
|
|
|
2025-05-28 00:07:59 +00:00
|
|
|
#[derive(Parser, Debug, Hash)]
|
|
|
|
|
#[command(version, about, long_about = None)]
|
|
|
|
|
pub struct Cli {
|
2025-05-28 13:42:31 +00:00
|
|
|
/// Timeout in seconds for HTTP actions (set 0 or invalid to disable)
|
|
|
|
|
#[arg(
|
|
|
|
|
short, long,
|
|
|
|
|
default_value = "10", value_name = "SECS",
|
|
|
|
|
value_parser = parse_seconds,
|
|
|
|
|
)]
|
|
|
|
|
timeout: Duration,
|
2025-05-28 00:07:59 +00:00
|
|
|
|
|
|
|
|
/// Protocol for Sharry instance
|
|
|
|
|
#[arg(
|
|
|
|
|
short, long,
|
2025-05-28 00:21:14 +00:00
|
|
|
default_value = "https", value_name = "VARIANT",
|
2025-05-28 13:42:31 +00:00
|
|
|
value_parser = PossibleValuesParser::new(["http", "https"]),
|
2025-05-28 00:07:59 +00:00
|
|
|
)]
|
2025-05-28 00:21:14 +00:00
|
|
|
pub protocol: String,
|
2025-05-28 00:07:59 +00:00
|
|
|
|
|
|
|
|
/// Name of the new share
|
2025-05-28 12:35:35 +00:00
|
|
|
#[arg(short, long, default_value = "ShrUpl Upload", value_name = "TEXT")]
|
2025-05-28 00:07:59 +00:00
|
|
|
pub name: String,
|
|
|
|
|
|
|
|
|
|
/// Description of the new share
|
2025-05-28 00:21:14 +00:00
|
|
|
#[arg(short, long, value_name = "TEXT")]
|
|
|
|
|
pub description: Option<String>,
|
2025-05-28 00:07:59 +00:00
|
|
|
|
|
|
|
|
/// Maximum number of views for the new share
|
2025-05-28 12:35:35 +00:00
|
|
|
#[arg(short, long, default_value_t = 100, value_name = "N")]
|
2025-05-28 00:21:14 +00:00
|
|
|
pub max_views: u32,
|
2025-05-28 00:07:59 +00:00
|
|
|
|
|
|
|
|
/// Chunk size for uploading, in MiB
|
2025-05-28 00:21:14 +00:00
|
|
|
#[arg(short, long, default_value_t = 10, value_name = "N")]
|
|
|
|
|
pub chunk_size: usize,
|
2025-05-28 00:07:59 +00:00
|
|
|
|
|
|
|
|
/// 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
|
2025-05-28 12:35:35 +00:00
|
|
|
#[arg(value_name = "FILE", required = true, value_parser = parse_sharry_file)]
|
|
|
|
|
pub files: Vec<File>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn parse_seconds(data: &str) -> Result<Duration, String> {
|
2025-05-28 13:42:31 +00:00
|
|
|
data.parse().or(Ok(0)).map(Duration::from_secs)
|
2025-05-28 12:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn parse_sharry_file(data: &str) -> Result<File, String> {
|
|
|
|
|
File::new(data).map_err(|e| e.to_string())
|
2025-05-28 00:07:59 +00:00
|
|
|
}
|
2025-05-28 13:42:31 +00:00
|
|
|
|
|
|
|
|
impl Cli {
|
|
|
|
|
pub fn get_timeout(&self) -> Option<Duration> {
|
|
|
|
|
(!self.timeout.is_zero()).then_some(self.timeout)
|
|
|
|
|
}
|
|
|
|
|
}
|