1#![cfg_attr(target_os = "windows", allow(unused, dead_code))]
2
3use anyhow::Result;
4use clap::{Parser, Subcommand};
5use std::path::PathBuf;
6
7#[derive(Parser)]
8#[command(disable_version_flag = true)]
9struct Cli {
10 #[command(subcommand)]
11 command: Option<Commands>,
12}
13
14#[derive(Subcommand)]
15enum Commands {
16 Run {
17 #[arg(long)]
18 log_file: PathBuf,
19 #[arg(long)]
20 pid_file: PathBuf,
21 #[arg(long)]
22 stdin_socket: PathBuf,
23 #[arg(long)]
24 stdout_socket: PathBuf,
25 #[arg(long)]
26 stderr_socket: PathBuf,
27 },
28 Proxy {
29 #[arg(long)]
30 reconnect: bool,
31 #[arg(long)]
32 identifier: String,
33 },
34 Version,
35}
36
37#[cfg(windows)]
38fn main() {
39 unimplemented!()
40}
41
42#[cfg(not(windows))]
43fn main() -> Result<()> {
44 use remote::proxy::ProxyLaunchError;
45 use remote_server::unix::{execute_proxy, execute_run};
46
47 let cli = Cli::parse();
48
49 match cli.command {
50 Some(Commands::Run {
51 log_file,
52 pid_file,
53 stdin_socket,
54 stdout_socket,
55 stderr_socket,
56 }) => execute_run(
57 log_file,
58 pid_file,
59 stdin_socket,
60 stdout_socket,
61 stderr_socket,
62 ),
63 Some(Commands::Proxy {
64 identifier,
65 reconnect,
66 }) => match execute_proxy(identifier, reconnect) {
67 Ok(_) => Ok(()),
68 Err(err) => {
69 if let Some(err) = err.downcast_ref::<ProxyLaunchError>() {
70 std::process::exit(err.to_exit_code());
71 }
72 Err(err)
73 }
74 },
75 Some(Commands::Version) => {
76 eprintln!("{}", env!("ZED_PKG_VERSION"));
77 Ok(())
78 }
79 None => {
80 eprintln!("usage: remote <run|proxy|version>");
81 std::process::exit(1);
82 }
83 }
84}