remote_server: move code from main.rs to remote_server.rs
This commit is contained in:
parent
b6fb9b10cf
commit
2e23edc179
2 changed files with 81 additions and 75 deletions
|
@ -1,6 +1,7 @@
|
|||
#![cfg_attr(target_os = "windows", allow(unused, dead_code))]
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
use clap::Parser;
|
||||
use remote_server::Commands;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Parser)]
|
||||
|
@ -21,29 +22,6 @@ struct Cli {
|
|||
printenv: bool,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
Run {
|
||||
#[arg(long)]
|
||||
log_file: PathBuf,
|
||||
#[arg(long)]
|
||||
pid_file: PathBuf,
|
||||
#[arg(long)]
|
||||
stdin_socket: PathBuf,
|
||||
#[arg(long)]
|
||||
stdout_socket: PathBuf,
|
||||
#[arg(long)]
|
||||
stderr_socket: PathBuf,
|
||||
},
|
||||
Proxy {
|
||||
#[arg(long)]
|
||||
reconnect: bool,
|
||||
#[arg(long)]
|
||||
identifier: String,
|
||||
},
|
||||
Version,
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn main() {
|
||||
unimplemented!()
|
||||
|
@ -51,11 +29,6 @@ fn main() {
|
|||
|
||||
#[cfg(not(windows))]
|
||||
fn main() -> anyhow::Result<()> {
|
||||
use anyhow::Context;
|
||||
use release_channel::{RELEASE_CHANNEL, ReleaseChannel};
|
||||
use remote::proxy::ProxyLaunchError;
|
||||
use remote_server::unix::{execute_proxy, execute_run};
|
||||
|
||||
let cli = Cli::parse();
|
||||
|
||||
if let Some(socket_path) = &cli.askpass {
|
||||
|
@ -73,51 +46,9 @@ fn main() -> anyhow::Result<()> {
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
match cli.command {
|
||||
Some(Commands::Run {
|
||||
log_file,
|
||||
pid_file,
|
||||
stdin_socket,
|
||||
stdout_socket,
|
||||
stderr_socket,
|
||||
}) => execute_run(
|
||||
log_file,
|
||||
pid_file,
|
||||
stdin_socket,
|
||||
stdout_socket,
|
||||
stderr_socket,
|
||||
),
|
||||
Some(Commands::Proxy {
|
||||
identifier,
|
||||
reconnect,
|
||||
}) => match execute_proxy(identifier, reconnect) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(err) => {
|
||||
if let Some(err) = err.downcast_ref::<ProxyLaunchError>() {
|
||||
std::process::exit(err.to_exit_code());
|
||||
}
|
||||
Err(err)
|
||||
}
|
||||
},
|
||||
Some(Commands::Version) => {
|
||||
let release_channel = *RELEASE_CHANNEL;
|
||||
match release_channel {
|
||||
ReleaseChannel::Stable | ReleaseChannel::Preview => {
|
||||
println!("{}", env!("ZED_PKG_VERSION"))
|
||||
}
|
||||
ReleaseChannel::Nightly | ReleaseChannel::Dev => {
|
||||
println!(
|
||||
"{}",
|
||||
option_env!("ZED_COMMIT_SHA").unwrap_or(release_channel.dev_name())
|
||||
)
|
||||
}
|
||||
};
|
||||
std::process::exit(0);
|
||||
}
|
||||
None => {
|
||||
eprintln!("usage: remote <run|proxy|version>");
|
||||
std::process::exit(1);
|
||||
}
|
||||
if let Some(command) = cli.command {
|
||||
remote_server::run(command)
|
||||
} else {
|
||||
Err(anyhow::anyhow!("usage: remote <run|proxy|version>"))
|
||||
}
|
||||
.context("exiting remote server due to error")
|
||||
}
|
||||
|
|
|
@ -6,4 +6,79 @@ pub mod unix;
|
|||
#[cfg(test)]
|
||||
mod remote_editing_tests;
|
||||
|
||||
use clap::Subcommand;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub use headless_project::{HeadlessAppState, HeadlessProject};
|
||||
|
||||
#[derive(Subcommand)]
|
||||
pub enum Commands {
|
||||
Run {
|
||||
#[arg(long)]
|
||||
log_file: PathBuf,
|
||||
#[arg(long)]
|
||||
pid_file: PathBuf,
|
||||
#[arg(long)]
|
||||
stdin_socket: PathBuf,
|
||||
#[arg(long)]
|
||||
stdout_socket: PathBuf,
|
||||
#[arg(long)]
|
||||
stderr_socket: PathBuf,
|
||||
},
|
||||
Proxy {
|
||||
#[arg(long)]
|
||||
reconnect: bool,
|
||||
#[arg(long)]
|
||||
identifier: String,
|
||||
},
|
||||
Version,
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
pub fn run(command: Commands) -> anyhow::Result<()> {
|
||||
use anyhow::Context;
|
||||
use release_channel::{RELEASE_CHANNEL, ReleaseChannel};
|
||||
use remote::proxy::ProxyLaunchError;
|
||||
use unix::{execute_proxy, execute_run};
|
||||
|
||||
match command {
|
||||
Commands::Run {
|
||||
log_file,
|
||||
pid_file,
|
||||
stdin_socket,
|
||||
stdout_socket,
|
||||
stderr_socket,
|
||||
} => execute_run(
|
||||
log_file,
|
||||
pid_file,
|
||||
stdin_socket,
|
||||
stdout_socket,
|
||||
stderr_socket,
|
||||
),
|
||||
Commands::Proxy {
|
||||
identifier,
|
||||
reconnect,
|
||||
} => execute_proxy(identifier, reconnect)
|
||||
.inspect_err(|err| {
|
||||
if let Some(err) = err.downcast_ref::<ProxyLaunchError>() {
|
||||
std::process::exit(err.to_exit_code());
|
||||
}
|
||||
})
|
||||
.context("running proxy on the remote server"),
|
||||
Commands::Version => {
|
||||
let release_channel = *RELEASE_CHANNEL;
|
||||
match release_channel {
|
||||
ReleaseChannel::Stable | ReleaseChannel::Preview => {
|
||||
println!("{}", env!("ZED_PKG_VERSION"))
|
||||
}
|
||||
ReleaseChannel::Nightly | ReleaseChannel::Dev => {
|
||||
println!(
|
||||
"{}",
|
||||
option_env!("ZED_COMMIT_SHA").unwrap_or(release_channel.dev_name())
|
||||
)
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue