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(any(feature = "serve", feature = "gateway"))]
17pub(crate) mod directory_listing;
18#[cfg(feature = "gateway")]
19pub(crate) mod gateway;
20#[cfg(feature = "grpc")]
21pub(crate) mod grpc;
22#[cfg(feature = "proxy")]
23pub(crate) mod proxy;
24#[cfg(feature = "serve")]
25pub(crate) mod serve;
26#[cfg(any(
27    feature = "proxy",
28    feature = "client",
29    feature = "serve",
30    feature = "bench",
31    feature = "gateway"
32))]
33pub(crate) mod tls;
34use clap::Parser;
35
36pub fn main() {
37    Cli::parse().run()
38}
39
40#[derive(Parser, Debug)]
41#[command(author, version, about)]
42pub enum Cli {
43    #[cfg(feature = "serve")]
44    /// Static file server and reverse proxy
45    Serve(serve::StaticCli),
46
47    #[cfg(all(unix, feature = "dev-server"))]
48    /// Development server for trillium applications
49    DevServer(dev_server::DevServer),
50
51    #[cfg(feature = "client")]
52    /// Make http requests using the trillium client
53    Client(client::ClientCli),
54
55    #[cfg(feature = "bench")]
56    /// Generate http load and report latency/throughput statistics
57    Bench(bench::BenchCli),
58
59    #[cfg(feature = "proxy")]
60    /// Run a http proxy
61    Proxy(proxy::ProxyCli),
62
63    #[cfg(feature = "gateway")]
64    /// Run a config-driven server: static files + proxy across one or more listeners
65    Gateway(gateway::GatewayCli),
66
67    #[cfg(feature = "grpc")]
68    /// Generate Rust modules from .proto service definitions
69    Grpc(grpc::GrpcCli),
70}
71
72impl Cli {
73    pub fn run(self) {
74        use Cli::*;
75        match self {
76            #[cfg(feature = "serve")]
77            Serve(s) => s.run(),
78            #[cfg(all(unix, feature = "dev-server"))]
79            DevServer(d) => d.run(),
80            #[cfg(feature = "client")]
81            Client(c) => c.run(),
82            #[cfg(feature = "bench")]
83            Bench(b) => b.run(),
84            #[cfg(feature = "proxy")]
85            Proxy(p) => p.run(),
86            #[cfg(feature = "gateway")]
87            Gateway(g) => g.run(),
88            #[cfg(feature = "grpc")]
89            Grpc(g) => g.run(),
90        }
91    }
92}
93
94#[cfg(any(feature = "proxy", feature = "serve", feature = "gateway"))]
95mod ratelimit;
96// `gateway` has its own TLS path (`gateway::sni`) and never touches `ServerTls`,
97// so this module is only built for `serve`/`proxy`.
98#[cfg(any(feature = "proxy", feature = "serve"))]
99mod server_tls;