Move flag requirements for credentials to subcommands that need it.
This commit is contained in:
37
src/main.rs
37
src/main.rs
@@ -23,12 +23,18 @@ mod web;
|
||||
enum Command {
|
||||
/// List albums for the user of the given credentials. Optionally title filter.
|
||||
ListAlbums {
|
||||
#[structopt(flatten)]
|
||||
auth: Auth,
|
||||
title_filter: Option<Regex>,
|
||||
},
|
||||
SearchMediaItems {
|
||||
#[structopt(flatten)]
|
||||
auth: Auth,
|
||||
album_id: String,
|
||||
},
|
||||
Sync {
|
||||
#[structopt(flatten)]
|
||||
auth: Auth,
|
||||
/// Optional album title to filter. Default will mirror all albums.
|
||||
#[structopt(short, long)]
|
||||
title_filter: Option<Regex>,
|
||||
@@ -44,6 +50,16 @@ enum Command {
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
struct Auth {
|
||||
/// Path to json file containing Google client ID and secrets for out of band auth flow.
|
||||
#[structopt(long)]
|
||||
credentials: PathBuf,
|
||||
/// Path to json file where photosync will store auth tokens refreshed from Google.
|
||||
#[structopt(long)]
|
||||
token_cache: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
#[structopt(
|
||||
name = "photosync",
|
||||
@@ -54,13 +70,6 @@ struct Opt {
|
||||
#[structopt(short, parse(from_occurrences))]
|
||||
verbose: usize,
|
||||
|
||||
/// Path to json file containing Google client ID and secrets for out of band auth flow.
|
||||
#[structopt(long)]
|
||||
credentials: PathBuf,
|
||||
/// Path to json file where photosync will store auth tokens refreshed from Google.
|
||||
#[structopt(long)]
|
||||
token_cache: PathBuf,
|
||||
|
||||
#[structopt(subcommand)]
|
||||
cmd: Command,
|
||||
}
|
||||
@@ -300,20 +309,26 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.init()
|
||||
.unwrap();
|
||||
debug!("opt: {:?}", opt);
|
||||
let client = new_client(&opt.credentials, &opt.token_cache)?;
|
||||
match opt.cmd {
|
||||
Command::ListAlbums { title_filter } => {
|
||||
Command::ListAlbums { auth, title_filter } => {
|
||||
let client = new_client(&auth.credentials, &auth.token_cache)?;
|
||||
print_albums(list_albums(&client, title_filter)?);
|
||||
Ok(())
|
||||
}
|
||||
Command::SearchMediaItems { album_id } => {
|
||||
Command::SearchMediaItems { auth, album_id } => {
|
||||
let client = new_client(&auth.credentials, &auth.token_cache)?;
|
||||
print_media_items(search_media_items(&client, &album_id)?);
|
||||
Ok(())
|
||||
}
|
||||
Command::Sync {
|
||||
auth,
|
||||
title_filter,
|
||||
output,
|
||||
} => sync_albums(&client, title_filter, output),
|
||||
} => {
|
||||
let client = new_client(&auth.credentials, &auth.token_cache)?;
|
||||
sync_albums(&client, title_filter, output)?;
|
||||
Ok(())
|
||||
}
|
||||
Command::Serve { addr, root } => serve(addr, root),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ use std::error::Error;
|
||||
use std::net::SocketAddr;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use log::info;
|
||||
use prometheus::Encoder;
|
||||
use warp;
|
||||
use warp::http::header::{HeaderMap, HeaderValue};
|
||||
@@ -37,7 +38,7 @@ pub fn run(addr: SocketAddr, root: PathBuf) -> Result<(), Box<dyn Error>> {
|
||||
//let api = api.or(index);
|
||||
let api = index;
|
||||
|
||||
let api = api.with(warp::log("moviewatcher"));
|
||||
let api = api.with(warp::log("photosync"));
|
||||
// We don't want metrics & heath checking filling up the logs, so we add this handler after
|
||||
// wrapping with the log filter.
|
||||
let routes = metrics().or(api);
|
||||
|
||||
Reference in New Issue
Block a user