main.rs

 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    },
26    Proxy {
27        #[arg(long)]
28        reconnect: bool,
29        #[arg(long)]
30        identifier: String,
31    },
32    Version,
33}
34
35#[cfg(windows)]
36fn main() {
37    unimplemented!()
38}
39
40#[cfg(not(windows))]
41fn main() -> Result<()> {
42    use remote::proxy::ProxyLaunchError;
43    use remote_server::unix::{execute_proxy, execute_run, init};
44
45    let cli = Cli::parse();
46
47    match cli.command {
48        Some(Commands::Run {
49            log_file,
50            pid_file,
51            stdin_socket,
52            stdout_socket,
53        }) => {
54            init(Some(log_file))?;
55            execute_run(pid_file, stdin_socket, stdout_socket)
56        }
57        Some(Commands::Proxy {
58            identifier,
59            reconnect,
60        }) => {
61            init(None)?;
62            match execute_proxy(identifier, reconnect) {
63                Ok(_) => Ok(()),
64                Err(err) => {
65                    if let Some(err) = err.downcast_ref::<ProxyLaunchError>() {
66                        std::process::exit(err.to_exit_code());
67                    }
68                    Err(err)
69                }
70            }
71        }
72        Some(Commands::Version) => {
73            eprintln!("{}", env!("ZED_PKG_VERSION"));
74            Ok(())
75        }
76        None => {
77            eprintln!("usage: remote <run|proxy|version>");
78            std::process::exit(1);
79        }
80    }
81}