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
pub mod build;
pub mod check;
pub mod completions;
pub mod download;
pub mod favorites;
pub mod info;
pub mod real_cugan;
pub mod search;
pub mod transform;
pub mod unzip;
pub mod update;
pub mod zip;

use std::path::Path;

use clap::ValueEnum;
use novel_api::Client;
use strum::AsRefStr;
use url::Url;

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, AsRefStr)]
pub enum Source {
    Sfacg,
    Ciweimao,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
pub enum Format {
    Pandoc,
    Mdbook,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
pub enum Convert {
    S2T,
    T2S,
    JP2T2S,
    CUSTOM,
}

fn default_cert_path() -> String {
    let mut home_path = novel_api::home_dir_path().unwrap();
    home_path.push(".mitmproxy");
    home_path.push("mitmproxy-ca-cert.pem");

    home_path.display().to_string()
}

fn set_options<T, E>(client: &mut T, proxy: &Option<Url>, no_proxy: &bool, cert: &Option<E>)
where
    T: Client,
    E: AsRef<Path>,
{
    if let Some(proxy) = proxy {
        client.proxy(proxy.clone());
    }

    if *no_proxy {
        client.no_proxy();
    }

    if let Some(cert) = cert {
        client.cert(cert)
    }
}