use std::env;
use anyhow::Result;
use clap::{Parser, Subcommand};
use ra_multiplex::config::Config;
use ra_multiplex::{ext, proxy, server};
use tracing::info;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Cli {
#[command(subcommand)]
command: Option<Cmd>,
}
#[derive(Subcommand, Debug)]
enum Cmd {
Client {
#[arg(
long = "server-path",
alias = "ra-mux-server",
env = "RA_MUX_SERVER",
default_value = "rust-analyzer",
name = "SERVER_PATH"
)]
server: String,
#[arg(name = "SERVER_ARGS")]
args: Vec<String>,
},
Server {},
Status {
#[clap(long = "json", default_value = "false")]
json: bool,
},
Config {},
Reload {},
}
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
let cli = Cli::parse();
let config = match Config::try_load() {
Ok(config) => {
config.init_logger();
config
}
Err(err) => {
let config = Config::default();
config.init_logger();
info!(?err, "cannot load config file, continuing with defaults");
config
}
};
match cli.command {
Some(Cmd::Server {}) => server::run(&config).await,
Some(Cmd::Client { server, args }) => proxy::run(&config, server, args).await,
Some(Cmd::Status { json }) => ext::status(&config, json).await,
Some(Cmd::Config {}) => ext::config(&config),
Some(Cmd::Reload {}) => ext::reload(&config).await,
None => {
let server_path = env::var("RA_MUX_SERVER").unwrap_or_else(|_| "rust-analyzer".into());
proxy::run(&config, server_path, vec![]).await
}
}
}