use std::path::PathBuf;
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(name = "yallm")]
#[command(author, version, about, long_about = None)]
pub struct Cli {
#[command(subcommand)]
pub command: Option<Commands>,
#[arg(short, long, default_value = "4000")]
pub port: u16,
#[arg(long, default_value = "127.0.0.1")]
pub host: String,
#[arg(long)]
pub tls_cert: Option<String>,
#[arg(long)]
pub tls_key: Option<String>,
#[arg(long)]
pub litellm_config: Option<PathBuf>,
}
#[derive(Subcommand)]
pub enum Commands {
Serve {
#[arg(short, long, default_value = "4000")]
port: u16,
#[arg(long, default_value = "127.0.0.1")]
host: String,
#[arg(long)]
tls_cert: Option<String>,
#[arg(long)]
tls_key: Option<String>,
#[arg(long)]
litellm_config: Option<PathBuf>,
},
}
impl Cli {
pub fn parse_args() -> Self {
Self::parse()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn parses_top_level_litellm_config() {
let cli = Cli::parse_from(["yallm", "--litellm-config", "litellm.yaml"]);
assert_eq!(cli.litellm_config, Some(PathBuf::from("litellm.yaml")));
}
#[test]
fn parses_serve_litellm_config() {
let cli = Cli::parse_from(["yallm", "serve", "--litellm-config", "litellm.yaml"]);
match cli.command {
Some(Commands::Serve { litellm_config, .. }) => {
assert_eq!(litellm_config, Some(PathBuf::from("litellm.yaml")));
}
_ => panic!("expected serve command"),
}
}
}