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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use clap::{value_t, App, Arg};
use std::error::Error;
use console::style;
use crate::{fetcher::{fetch_many_images, fetch_single_image}, vars::{BASE_URL, BASE_URL_MANY}};

pub fn cli() -> Result<(), Box<dyn Error>> {
    let matches = App::new("waifu4me")
        .version("0.1.7")
        .author("kenjitheman")
        .about("CLI tool for waifu image url fetching using waifu.pics API")
        .arg(
            Arg::with_name("type")
                .short("t")
                .long("type")
                .value_name("TYPE")
                .help("Specify the type of the content to fetch.\n->")
                .possible_values(&["sfw", "nsfw"])
                .takes_value(true)
                .required(true)
                .case_insensitive(true),
        )
        .arg(
            Arg::with_name("category")
                .short("c")
                .long("category")
                .value_name("CATEGORY")
                .help("Specify the category of the waifu to fetch.\n->")
                .possible_values(&[ 
                    "For SFW:", "waifu", 
                    "nekoshinobu", "megumin", "bully", "cuddle",
                    "cry", "hug", "awoo", "kiss", "lick", "pat", "smug", 
                    "yeet", "blush", "smile","wave", "highfive", "handhold", 
                    "nom", "bite", "glomp", "bonk", "slap", "kill", "kick",
                    "happy", "wink", "poke", "dance", "cringe", 
                    "\nFor NSFW:", "waifu", "neko", "trap", "blowjob"
                ])
                .takes_value(true)
                .required(true)
                .case_insensitive(true),
        )
        .arg(
            Arg::with_name("many")
                .short("m")
                .long("many")
                .value_name("MANY")
                .help("Specify the amount of waifus to fetch (true for many).\n->")
                .required(false)
                .takes_value(true)
                .possible_values(&["true", "false"])
                .default_value("false")
                .case_insensitive(true),
        )
        .get_matches();

    let base_url = BASE_URL;
    let base_url_many = BASE_URL_MANY;
    let _type = value_t!(matches.value_of("type"), String)?;
    let category = value_t!(matches.value_of("category"), String)?;
    let many = value_t!(matches.value_of("many"), bool)?;

    if many {
        fetch_many_images(base_url_many, _type, category)?;
    } else {
        let url = format!("{}/{}/{}", base_url, _type, category);
        println!(
            "[{}] Your request: {}",
            style("INFO").green().bold().italic(),
            style(&url).cyan().bold().italic()
        );

        fetch_single_image(&url)?;
    }

    Ok(())
}