mirror of
https://github.com/joshuadavidthomas/django-language-server.git
synced 2025-08-04 01:58:18 +00:00
39 lines
1,015 B
Rust
39 lines
1,015 B
Rust
use crate::args::Args;
|
|
use crate::commands::{Command, DjlsCommand};
|
|
use crate::exit::Exit;
|
|
use anyhow::Result;
|
|
use clap::Parser;
|
|
|
|
/// Main CLI structure that defines the command-line interface
|
|
#[derive(Parser)]
|
|
#[command(name = "djls")]
|
|
#[command(version, about)]
|
|
pub struct Cli {
|
|
#[command(subcommand)]
|
|
pub command: DjlsCommand,
|
|
|
|
#[command(flatten)]
|
|
pub args: Args,
|
|
}
|
|
|
|
/// Parse CLI arguments, execute the chosen command, and handle results
|
|
pub fn run(args: Vec<String>) -> Result<()> {
|
|
let cli = Cli::try_parse_from(args).unwrap_or_else(|e| {
|
|
e.exit();
|
|
});
|
|
|
|
let result = match &cli.command {
|
|
DjlsCommand::Serve(cmd) => cmd.execute(&cli.args),
|
|
};
|
|
|
|
match result {
|
|
Ok(exit) => exit.process_exit(),
|
|
Err(e) => {
|
|
let mut msg = e.to_string();
|
|
if let Some(source) = e.source() {
|
|
msg += &format!(", caused by {}", source);
|
|
}
|
|
Exit::error().with_message(msg).process_exit()
|
|
}
|
|
}
|
|
}
|