remote_server.rs

 1mod headless_project;
 2
 3#[cfg(not(windows))]
 4pub mod unix;
 5
 6#[cfg(test)]
 7mod remote_editing_tests;
 8
 9use clap::Subcommand;
10use std::path::PathBuf;
11
12pub use headless_project::{HeadlessAppState, HeadlessProject};
13
14#[derive(Subcommand)]
15pub enum 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(not(windows))]
38pub fn run(command: Commands) -> anyhow::Result<()> {
39    use anyhow::Context;
40    use release_channel::{RELEASE_CHANNEL, ReleaseChannel};
41    use unix::{ExecuteProxyError, execute_proxy, execute_run};
42
43    match command {
44        Commands::Run {
45            log_file,
46            pid_file,
47            stdin_socket,
48            stdout_socket,
49            stderr_socket,
50        } => execute_run(
51            log_file,
52            pid_file,
53            stdin_socket,
54            stdout_socket,
55            stderr_socket,
56        ),
57        Commands::Proxy {
58            identifier,
59            reconnect,
60        } => execute_proxy(identifier, reconnect)
61            .inspect_err(|err| {
62                if let ExecuteProxyError::ServerNotRunning(err) = err {
63                    std::process::exit(err.to_exit_code());
64                }
65            })
66            .context("running proxy on the remote server"),
67        Commands::Version => {
68            let release_channel = *RELEASE_CHANNEL;
69            match release_channel {
70                ReleaseChannel::Stable | ReleaseChannel::Preview => {
71                    println!("{}", env!("ZED_PKG_VERSION"))
72                }
73                ReleaseChannel::Nightly | ReleaseChannel::Dev => {
74                    println!(
75                        "{}",
76                        option_env!("ZED_COMMIT_SHA").unwrap_or(release_channel.dev_name())
77                    )
78                }
79            };
80            Ok(())
81        }
82    }
83}