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}
12
13#[derive(Subcommand)]
14enum Commands {
15 Run {
16 #[arg(long)]
17 log_file: PathBuf,
18 #[arg(long)]
19 pid_file: PathBuf,
20 #[arg(long)]
21 stdin_socket: PathBuf,
22 #[arg(long)]
23 stdout_socket: PathBuf,
24 #[arg(long)]
25 stderr_socket: PathBuf,
26 },
27 Proxy {
28 #[arg(long)]
29 reconnect: bool,
30 #[arg(long)]
31 identifier: String,
32 },
33 Version,
34}
35
36#[cfg(windows)]
37fn main() {
38 unimplemented!()
39}
40
41#[cfg(not(windows))]
42fn main() {
43 use release_channel::{RELEASE_CHANNEL, ReleaseChannel};
44 use remote::proxy::ProxyLaunchError;
45 use remote_server::unix::{execute_proxy, execute_run};
46
47 let cli = Cli::parse();
48
49 let result = 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 let release_channel = *RELEASE_CHANNEL;
77 match release_channel {
78 ReleaseChannel::Stable | ReleaseChannel::Preview => {
79 println!("{}", env!("ZED_PKG_VERSION"))
80 }
81 ReleaseChannel::Nightly | ReleaseChannel::Dev => {
82 println!(
83 "{}",
84 option_env!("ZED_COMMIT_SHA").unwrap_or(release_channel.dev_name())
85 )
86 }
87 };
88 std::process::exit(0);
89 }
90 None => {
91 eprintln!("usage: remote <run|proxy|version>");
92 std::process::exit(1);
93 }
94 };
95 if let Err(error) = result {
96 log::error!("exiting due to error: {}", error);
97 std::process::exit(1);
98 }
99}