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::{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).context("running proxy on the remote server"),
61        Commands::Version => {
62            let release_channel = *RELEASE_CHANNEL;
63            match release_channel {
64                ReleaseChannel::Stable | ReleaseChannel::Preview => {
65                    println!("{}", env!("ZED_PKG_VERSION"))
66                }
67                ReleaseChannel::Nightly | ReleaseChannel::Dev => {
68                    let commit_sha =
69                        option_env!("ZED_COMMIT_SHA").unwrap_or(release_channel.dev_name());
70                    let build_id = option_env!("ZED_BUILD_ID");
71                    if let Some(build_id) = build_id {
72                        println!("{}+{}", build_id, commit_sha)
73                    } else {
74                        println!("{commit_sha}");
75                    }
76                }
77            };
78            Ok(())
79        }
80    }
81}