Skip to main content

yallm_cli/
lib.rs

1//! yallm CLI implementation
2
3use std::path::PathBuf;
4
5use clap::{Parser, Subcommand};
6
7/// Unified LLM API converter proxy server
8#[derive(Parser)]
9#[command(name = "yallm")]
10#[command(author, version, about, long_about = None)]
11pub struct Cli {
12    #[command(subcommand)]
13    pub command: Option<Commands>,
14
15    /// Port to listen on
16    #[arg(short, long, default_value = "4000")]
17    pub port: u16,
18
19    /// Host to bind to
20    #[arg(long, default_value = "127.0.0.1")]
21    pub host: String,
22
23    /// TLS certificate path (PEM); enables HTTPS when set with --tls-key
24    #[arg(long)]
25    pub tls_cert: Option<String>,
26
27    /// TLS private key path (PEM)
28    #[arg(long)]
29    pub tls_key: Option<String>,
30
31    /// Path to a LiteLLM config.yaml file
32    #[arg(long)]
33    pub litellm_config: Option<PathBuf>,
34}
35
36#[derive(Subcommand)]
37pub enum Commands {
38    /// Start the proxy server
39    Serve {
40        /// Port to listen on
41        #[arg(short, long, default_value = "4000")]
42        port: u16,
43
44        /// Host to bind to
45        #[arg(long, default_value = "127.0.0.1")]
46        host: String,
47
48        /// TLS certificate path (PEM); enables HTTPS when set with --tls-key
49        #[arg(long)]
50        tls_cert: Option<String>,
51
52        /// TLS private key path (PEM)
53        #[arg(long)]
54        tls_key: Option<String>,
55
56        /// Path to a LiteLLM config.yaml file
57        #[arg(long)]
58        litellm_config: Option<PathBuf>,
59    },
60}
61
62impl Cli {
63    pub fn parse_args() -> Self {
64        Self::parse()
65    }
66}
67
68#[cfg(test)]
69mod tests {
70    use super::*;
71
72    #[test]
73    fn parses_top_level_litellm_config() {
74        let cli = Cli::parse_from(["yallm", "--litellm-config", "litellm.yaml"]);
75
76        assert_eq!(cli.litellm_config, Some(PathBuf::from("litellm.yaml")));
77    }
78
79    #[test]
80    fn parses_serve_litellm_config() {
81        let cli = Cli::parse_from(["yallm", "serve", "--litellm-config", "litellm.yaml"]);
82
83        match cli.command {
84            Some(Commands::Serve { litellm_config, .. }) => {
85                assert_eq!(litellm_config, Some(PathBuf::from("litellm.yaml")));
86            }
87            _ => panic!("expected serve command"),
88        }
89    }
90}