|  | 
|  | 1 | +//! list subcomAmand - List leeAtcode problems | 
|  | 2 | +//! | 
|  | 3 | +//! ``` | 
|  | 4 | +//! leetcode-list  | 
|  | 5 | +//! List problems | 
|  | 6 | +//!  | 
|  | 7 | +//! USAGE: | 
|  | 8 | +//! leetcode list [FLAGS] | 
|  | 9 | +//!  | 
|  | 10 | +//! FLAGS: | 
|  | 11 | +//! -w, --all List all problems | 
|  | 12 | +//! -a, --algorithms List algorithm problems | 
|  | 13 | +//! -d, --database List database problems | 
|  | 14 | +//! -s, --shell List shell problems | 
|  | 15 | +//! -h, --help Prints help information | 
|  | 16 | +//! -V, --version Prints version information | 
|  | 17 | +//! ``` | 
|  | 18 | +use clap::{SubCommand, App, Arg, ArgMatches}; | 
|  | 19 | +use crate::plugins::leetcode; | 
|  | 20 | +use super::Command; | 
|  | 21 | + | 
|  | 22 | +/// abstract `list` command in `leetcode-cli`. | 
|  | 23 | +pub struct ListCommand; | 
|  | 24 | + | 
|  | 25 | +/// implement Command trait for `list` | 
|  | 26 | +impl Command for ListCommand { | 
|  | 27 | + /// `list` command usage | 
|  | 28 | + fn usage<'a, 'list>() -> App<'a, 'list> { | 
|  | 29 | + SubCommand::with_name("list") | 
|  | 30 | + .about("List problems") | 
|  | 31 | + .arg(Arg::with_name("all") | 
|  | 32 | + .short("w") | 
|  | 33 | + .long("all") | 
|  | 34 | + .help("List all problems") | 
|  | 35 | + .display_order(1) | 
|  | 36 | + ) | 
|  | 37 | + .arg(Arg::with_name("algorithms") | 
|  | 38 | + .short("a") | 
|  | 39 | + .long("algorithm") | 
|  | 40 | + .help("List algorithm problems") | 
|  | 41 | + .display_order(2) | 
|  | 42 | + ) | 
|  | 43 | + .arg(Arg::with_name("database") | 
|  | 44 | + .short("d") | 
|  | 45 | + .long("database") | 
|  | 46 | + .help("List database problems") | 
|  | 47 | + .display_order(3) | 
|  | 48 | + ) | 
|  | 49 | + .arg(Arg::with_name("shell") | 
|  | 50 | + .short("s") | 
|  | 51 | + .long("shell") | 
|  | 52 | + .help("List shell problems") | 
|  | 53 | + .display_order(4) | 
|  | 54 | + ) | 
|  | 55 | + } | 
|  | 56 | + | 
|  | 57 | + /// `list` command handler | 
|  | 58 | + /// List commands contains "algorithm", "database", and "shell" methods. | 
|  | 59 | + /// | 
|  | 60 | + /// because of...leetcode content these three categories. | 
|  | 61 | + fn handler(m: &ArgMatches) { | 
|  | 62 | + let cli = leetcode::LeetCode::new(); | 
|  | 63 | + if m.is_present("algorithms") { | 
|  | 64 | + let mut res = cli.get_user_info(); | 
|  | 65 | + info!("{:?}", res.text()); | 
|  | 66 | + } else if m.is_present("database") { | 
|  | 67 | + let mut res = cli.get_user_info(); | 
|  | 68 | + info!("{:?}", res.text()); | 
|  | 69 | + } else if m.is_present("shell") { | 
|  | 70 | + let mut res = cli.get_user_info(); | 
|  | 71 | + info!("{:?}", res.text()); | 
|  | 72 | + } else { | 
|  | 73 | + let mut res = cli.get_user_info(); | 
|  | 74 | + info!("{:?}", res.text()); | 
|  | 75 | + } | 
|  | 76 | + } | 
|  | 77 | +} | 
0 commit comments