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
#![forbid(unsafe_code)]
#![deny(
    clippy::dbg_macro,
    missing_debug_implementations,
    nonstandard_style,
    missing_copy_implementations,
    unused_qualifications
)]

#[cfg(feature = "client")]
pub(crate) mod client;
#[cfg(any(feature = "proxy", feature = "client", feature = "serve"))]
pub(crate) mod client_tls;
#[cfg(all(unix, feature = "dev-server"))]
pub(crate) mod dev_server;
#[cfg(feature = "proxy")]
pub(crate) mod proxy;
#[cfg(feature = "serve")]
pub(crate) mod serve;
use clap::Parser;

pub fn main() {
    Cli::parse().run()
}

#[derive(Parser, Debug)]
#[command(author, version, about)]
pub enum Cli {
    #[cfg(feature = "serve")]
    /// Static file server and reverse proxy
    Serve(serve::StaticCli),

    #[cfg(all(unix, feature = "dev-server"))]
    /// Development server for trillium applications
    DevServer(dev_server::DevServer),

    #[cfg(feature = "client")]
    /// Make http requests using the trillium client
    Client(client::ClientCli),

    #[cfg(feature = "proxy")]
    /// Run a http proxy
    Proxy(proxy::ProxyCli),
}

impl Cli {
    pub fn run(self) {
        use Cli::*;
        match self {
            #[cfg(feature = "serve")]
            Serve(s) => s.run(),
            #[cfg(all(unix, feature = "dev-server"))]
            DevServer(d) => d.run(),
            #[cfg(feature = "client")]
            Client(c) => c.run(),
            #[cfg(feature = "proxy")]
            Proxy(p) => p.run(),
        }
    }
}

#[cfg(any(feature = "proxy", feature = "serve"))]
mod server_tls;