From 0530bf42f65752eefb7a5a55d4a6c64b5dd1535c Mon Sep 17 00:00:00 2001 From: Emi Simpson Date: Fri, 12 Aug 2022 16:14:30 -0400 Subject: [PATCH] Add subcommands --- src/main.rs | 20 +++++++++++++++++--- src/parse.rs | 28 +++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4fefb44..58c7812 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ use std::path::Path; use errors::AviaryError; use itertools::{Itertools, Either}; +use parse::{CreateArgs, Command, DownloadArgs}; use ::protobuf::Message; fn trim_url<'a>(base_url: &str, url: &'a str) -> Option<&'a str> { @@ -33,6 +34,13 @@ fn trim_url<'a>(base_url: &str, url: &'a str) -> Option<&'a str> { fn main() { let args: parse::Args = argh::from_env(); + match args.command { + Command::Create(create_args) => create(&args.server, create_args), + Command::Download(download_args) => download(&args.server, download_args), + } +} + +fn create(server: &str, args: CreateArgs) { print!("Checking files..."); let (files, errors): (Vec<_>, Vec<_>) = args.images.iter() .map(Path::new) @@ -61,10 +69,10 @@ fn main() { } else { println!(" \x1b[32mDone!\n"); let agent = upload::get_agent(); - let full_server = if args.server.starts_with("http") { - Cow::Borrowed(&args.server) + let full_server = if server.starts_with("http") { + Cow::Borrowed(server) } else { - Cow::Owned(format!("https://{}", args.server)) + Cow::Owned(format!("https://{}", server)) }; let index_url = files.into_iter() .inspect(|(path, _)| print!("\x1b[36m{}\x1b[0m\n\x1b[37m├─\x1b[0m Reading... ", path.display())) @@ -142,3 +150,9 @@ fn main() { } } } + +fn download(server: &str, args: DownloadArgs) { + drop(server); + drop(args); + todo!("Unimplemented... yet") +} diff --git a/src/parse.rs b/src/parse.rs index a2ec87d..b6c8d94 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -3,15 +3,37 @@ use argh_derive::FromArgs; #[derive(FromArgs)] /// Create Aviary galleries pub struct Args { - /// the title of the gallery - #[argh(option, short = 't')] - pub title: Option, /// the null pointer server to use #[argh(option, short = 's', default = "\"envs.sh\".to_owned()")] pub server: String, + #[argh(subcommand)] + pub command: Command, +} + +#[derive(FromArgs)] +#[argh(subcommand)] +pub enum Command { + Create(CreateArgs), + Download(DownloadArgs), +} + +#[derive(FromArgs)] +#[argh(subcommand, name = "create")] +/// upload a series of images to a new gallery +pub struct CreateArgs { + /// the title of the gallery + #[argh(option, short = 't')] + pub title: Option, + /// A list of image files to post #[argh(positional)] pub images: Vec, } + +#[derive(FromArgs)] +#[argh(subcommand, name = "download")] +/// download a gallery +pub struct DownloadArgs { +}