Add subcommands
This commit is contained in:
parent
eb79a65500
commit
0530bf42f6
20
src/main.rs
20
src/main.rs
|
@ -12,6 +12,7 @@ use std::path::Path;
|
||||||
|
|
||||||
use errors::AviaryError;
|
use errors::AviaryError;
|
||||||
use itertools::{Itertools, Either};
|
use itertools::{Itertools, Either};
|
||||||
|
use parse::{CreateArgs, Command, DownloadArgs};
|
||||||
use ::protobuf::Message;
|
use ::protobuf::Message;
|
||||||
|
|
||||||
fn trim_url<'a>(base_url: &str, url: &'a str) -> Option<&'a str> {
|
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() {
|
fn main() {
|
||||||
let args: parse::Args = argh::from_env();
|
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...");
|
print!("Checking files...");
|
||||||
let (files, errors): (Vec<_>, Vec<_>) = args.images.iter()
|
let (files, errors): (Vec<_>, Vec<_>) = args.images.iter()
|
||||||
.map(Path::new)
|
.map(Path::new)
|
||||||
|
@ -61,10 +69,10 @@ fn main() {
|
||||||
} else {
|
} else {
|
||||||
println!(" \x1b[32mDone!\n");
|
println!(" \x1b[32mDone!\n");
|
||||||
let agent = upload::get_agent();
|
let agent = upload::get_agent();
|
||||||
let full_server = if args.server.starts_with("http") {
|
let full_server = if server.starts_with("http") {
|
||||||
Cow::Borrowed(&args.server)
|
Cow::Borrowed(server)
|
||||||
} else {
|
} else {
|
||||||
Cow::Owned(format!("https://{}", args.server))
|
Cow::Owned(format!("https://{}", server))
|
||||||
};
|
};
|
||||||
let index_url = files.into_iter()
|
let index_url = files.into_iter()
|
||||||
.inspect(|(path, _)| print!("\x1b[36m{}\x1b[0m\n\x1b[37m├─\x1b[0m Reading... ", path.display()))
|
.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")
|
||||||
|
}
|
||||||
|
|
28
src/parse.rs
28
src/parse.rs
|
@ -3,15 +3,37 @@ use argh_derive::FromArgs;
|
||||||
#[derive(FromArgs)]
|
#[derive(FromArgs)]
|
||||||
/// Create Aviary galleries
|
/// Create Aviary galleries
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
/// the title of the gallery
|
|
||||||
#[argh(option, short = 't')]
|
|
||||||
pub title: Option<String>,
|
|
||||||
|
|
||||||
/// the null pointer server to use
|
/// the null pointer server to use
|
||||||
#[argh(option, short = 's', default = "\"envs.sh\".to_owned()")]
|
#[argh(option, short = 's', default = "\"envs.sh\".to_owned()")]
|
||||||
pub server: String,
|
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
|
/// A list of image files to post
|
||||||
#[argh(positional)]
|
#[argh(positional)]
|
||||||
pub images: Vec<String>,
|
pub images: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(FromArgs)]
|
||||||
|
#[argh(subcommand, name = "download")]
|
||||||
|
/// download a gallery
|
||||||
|
pub struct DownloadArgs {
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue