Skip to main content

trillium_cli/
lib.rs

1#![forbid(unsafe_code)]
2#![deny(
3    clippy::dbg_macro,
4    missing_debug_implementations,
5    nonstandard_style,
6    missing_copy_implementations,
7    unused_qualifications
8)]
9
10#[cfg(feature = "bench")]
11pub(crate) mod bench;
12#[cfg(feature = "client")]
13pub(crate) mod client;
14#[cfg(all(unix, feature = "dev-server"))]
15pub(crate) mod dev_server;
16#[cfg(feature = "proxy")]
17pub(crate) mod proxy;
18#[cfg(feature = "serve")]
19pub(crate) mod serve;
20#[cfg(any(
21    feature = "proxy",
22    feature = "client",
23    feature = "serve",
24    feature = "bench"
25))]
26pub(crate) mod tls;
27use clap::Parser;
28
29pub fn main() {
30    Cli::parse().run()
31}
32
33#[derive(Parser, Debug)]
34#[command(author, version, about)]
35pub enum Cli {
36    #[cfg(feature = "serve")]
37    /// Static file server and reverse proxy
38    Serve(serve::StaticCli),
39
40    #[cfg(all(unix, feature = "dev-server"))]
41    /// Development server for trillium applications
42    DevServer(dev_server::DevServer),
43
44    #[cfg(feature = "client")]
45    /// Make http requests using the trillium client
46    Client(client::ClientCli),
47
48    #[cfg(feature = "bench")]
49    /// Generate http load and report latency/throughput statistics
50    Bench(bench::BenchCli),
51
52    #[cfg(feature = "proxy")]
53    /// Run a http proxy
54    Proxy(proxy::ProxyCli),
55}
56
57impl Cli {
58    pub fn run(self) {
59        use Cli::*;
60        match self {
61            #[cfg(feature = "serve")]
62            Serve(s) => s.run(),
63            #[cfg(all(unix, feature = "dev-server"))]
64            DevServer(d) => d.run(),
65            #[cfg(feature = "client")]
66            Client(c) => c.run(),
67            #[cfg(feature = "bench")]
68            Bench(b) => b.run(),
69            #[cfg(feature = "proxy")]
70            Proxy(p) => p.run(),
71        }
72    }
73}
74
75#[cfg(any(feature = "proxy", feature = "serve"))]
76mod server_tls;