40 lines
1005 B
Rust
40 lines
1005 B
Rust
use clap::{App, ArgMatches, SubCommand as ClapSubCommand};
|
|
use failure::Fallible;
|
|
|
|
use crate::cmd::{ArgMatchResult, CommandInvocation};
|
|
|
|
#[derive(Debug)]
|
|
struct Invocation {}
|
|
|
|
define_subcommand! {
|
|
fn decorate_app<'a>(&self, app: App<'a, 'a>) -> App<'a, 'a> {
|
|
app.subcommand(ClapSubCommand::with_name("sync").about("sync with the server"))
|
|
}
|
|
|
|
fn arg_match<'a>(&self, matches: &ArgMatches<'a>) -> ArgMatchResult {
|
|
match matches.subcommand() {
|
|
("sync", _) => ArgMatchResult::Ok(Box::new(Invocation {})),
|
|
_ => ArgMatchResult::None,
|
|
}
|
|
}
|
|
}
|
|
|
|
subcommand_invocation! {
|
|
fn run(&self, command: &CommandInvocation) -> Fallible<()> {
|
|
let mut replica = command.get_replica()?;
|
|
let mut server = command.get_server()?;
|
|
replica.sync(&mut server)?;
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod test {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn parse_command() {
|
|
with_subcommand_invocation!(vec!["task", "sync"], |_inv| {});
|
|
}
|
|
}
|