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 remote::proxy::ProxyLaunchError;
44 use remote_server::unix::{execute_proxy, execute_run};
45
46 let cli = Cli::parse();
47
48 let result = match cli.command {
49 Some(Commands::Run {
50 log_file,
51 pid_file,
52 stdin_socket,
53 stdout_socket,
54 stderr_socket,
55 }) => execute_run(
56 log_file,
57 pid_file,
58 stdin_socket,
59 stdout_socket,
60 stderr_socket,
61 ),
62 Some(Commands::Proxy {
63 identifier,
64 reconnect,
65 }) => match execute_proxy(identifier, reconnect) {
66 Ok(_) => Ok(()),
67 Err(err) => {
68 if let Some(err) = err.downcast_ref::<ProxyLaunchError>() {
69 std::process::exit(err.to_exit_code());
70 }
71 Err(err)
72 }
73 },
74 Some(Commands::Version) => {
75 if let Some(build_sha) = option_env!("ZED_COMMIT_SHA") {
76 println!("{}", build_sha);
77 } else {
78 println!("{}", env!("ZED_PKG_VERSION"));
79 }
80
81 std::process::exit(0);
82 }
83 None => {
84 eprintln!("usage: remote <run|proxy|version>");
85 std::process::exit(1);
86 }
87 };
88 if let Err(error) = result {
89 log::error!("exiting due to error: {}", error);
90 std::process::exit(1);
91 }
92}