1#![cfg_attr(target_os = "windows", allow(unused, dead_code))]
2
3use clap::{Parser, Subcommand};
4use std::path::PathBuf;
5
6#[derive(Parser)]
7#[command(disable_version_flag = true)]
8struct Cli {
9 #[command(subcommand)]
10 command: Option<Commands>,
11 /// Used for SSH/Git password authentication, to remove the need for netcat as a dependency,
12 /// by having Zed act like netcat communicating over a Unix socket.
13 #[arg(long, hide = true)]
14 askpass: Option<String>,
15}
16
17#[derive(Subcommand)]
18enum Commands {
19 Run {
20 #[arg(long)]
21 log_file: PathBuf,
22 #[arg(long)]
23 pid_file: PathBuf,
24 #[arg(long)]
25 stdin_socket: PathBuf,
26 #[arg(long)]
27 stdout_socket: PathBuf,
28 #[arg(long)]
29 stderr_socket: PathBuf,
30 },
31 Proxy {
32 #[arg(long)]
33 reconnect: bool,
34 #[arg(long)]
35 identifier: String,
36 },
37 Version,
38}
39
40#[cfg(windows)]
41fn main() {
42 unimplemented!()
43}
44
45#[cfg(not(windows))]
46fn main() {
47 use release_channel::{RELEASE_CHANNEL, ReleaseChannel};
48 use remote::proxy::ProxyLaunchError;
49 use remote_server::unix::{execute_proxy, execute_run};
50
51 let cli = Cli::parse();
52
53 if let Some(socket_path) = &cli.askpass {
54 askpass::main(socket_path);
55 return;
56 }
57
58 let result = match cli.command {
59 Some(Commands::Run {
60 log_file,
61 pid_file,
62 stdin_socket,
63 stdout_socket,
64 stderr_socket,
65 }) => execute_run(
66 log_file,
67 pid_file,
68 stdin_socket,
69 stdout_socket,
70 stderr_socket,
71 ),
72 Some(Commands::Proxy {
73 identifier,
74 reconnect,
75 }) => match execute_proxy(identifier, reconnect) {
76 Ok(_) => Ok(()),
77 Err(err) => {
78 if let Some(err) = err.downcast_ref::<ProxyLaunchError>() {
79 std::process::exit(err.to_exit_code());
80 }
81 Err(err)
82 }
83 },
84 Some(Commands::Version) => {
85 let release_channel = *RELEASE_CHANNEL;
86 match release_channel {
87 ReleaseChannel::Stable | ReleaseChannel::Preview => {
88 println!("{}", env!("ZED_PKG_VERSION"))
89 }
90 ReleaseChannel::Nightly | ReleaseChannel::Dev => {
91 println!(
92 "{}",
93 option_env!("ZED_COMMIT_SHA").unwrap_or(release_channel.dev_name())
94 )
95 }
96 };
97 std::process::exit(0);
98 }
99 None => {
100 eprintln!("usage: remote <run|proxy|version>");
101 std::process::exit(1);
102 }
103 };
104 if let Err(error) = result {
105 log::error!("exiting due to error: {}", error);
106 std::process::exit(1);
107 }
108}