Add subcommands

This commit is contained in:
Emi Simpson 2022-08-12 16:14:30 -04:00
parent eb79a65500
commit 0530bf42f6
Signed by: Emi
GPG key ID: A12F2C2FFDC3D847
2 changed files with 42 additions and 6 deletions

View file

@ -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")
}

View file

@ -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<String>,
/// 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<String>,
/// A list of image files to post
#[argh(positional)]
pub images: Vec<String>,
}
#[derive(FromArgs)]
#[argh(subcommand, name = "download")]
/// download a gallery
pub struct DownloadArgs {
}