1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
//! Exec command
use super::Command;
use crate::Error;
use async_trait::async_trait;
use clap::{Arg, ArgMatches, Command as ClapCommand};
/// Abstract Exec Command
///
/// ```sh
/// leetcode-exec
/// Submit solution
///
/// USAGE:
/// leetcode exec <id>
///
/// FLAGS:
/// -h, --help Prints help information
/// -V, --version Prints version information
///
/// ARGS:
/// <id> question id
/// ```
pub struct ExecCommand;
#[async_trait]
impl Command for ExecCommand {
/// `exec` usage
fn usage() -> ClapCommand {
ClapCommand::new("exec")
.about("Submit solution")
.visible_alias("x")
.arg(
Arg::new("id")
.num_args(1)
.required(true)
.value_parser(clap::value_parser!(i32))
.help("question id"),
)
}
/// `exec` handler
async fn handler(m: &ArgMatches) -> Result<(), crate::Error> {
use crate::cache::{Cache, Run};
let id: i32 = *m.get_one::<i32>("id").ok_or(Error::NoneError)?;
let cache = Cache::new()?;
let res = cache.exec_problem(id, Run::Submit, None).await?;
println!("{}", res);
Ok(())
}
}