use shell_tunnel::{api::serve, logging, parse_args, print_help, print_version, Config};
use tracing::info;
#[tokio::main]
async fn main() -> shell_tunnel::Result<()> {
let args = match parse_args() {
Ok(args) => args,
Err(e) => {
eprintln!("Error: {}", e);
eprintln!("Use --help for usage information");
std::process::exit(1);
}
};
if args.help {
print_help();
return Ok(());
}
if args.version {
print_version();
return Ok(());
}
#[cfg(feature = "self-update")]
{
use shell_tunnel::update;
if args.check_update {
match update::check_update() {
Ok(info) => {
println!("Current version: {}", info.current);
println!("Latest version: {}", info.latest);
if info.update_available {
println!("\nUpdate available! Run with --update to install.");
} else {
println!("\nYou are running the latest version.");
}
}
Err(e) => {
eprintln!("Failed to check for updates: {}", e);
std::process::exit(1);
}
}
return Ok(());
}
if args.update {
println!("Checking for updates...");
match update::self_update() {
Ok(true) => {
println!("Successfully updated! Please restart shell-tunnel.");
}
Ok(false) => {
println!("Already running the latest version.");
}
Err(e) => {
eprintln!("Update failed: {}", e);
std::process::exit(1);
}
}
return Ok(());
}
}
let config = match Config::load(&args) {
Ok(config) => config,
Err(e) => {
eprintln!("Configuration error: {}", e);
std::process::exit(1);
}
};
std::env::set_var("RUST_LOG", config.log_filter());
logging::init();
info!("shell-tunnel v{}", env!("CARGO_PKG_VERSION"));
#[cfg(feature = "self-update")]
if !args.no_update_check {
shell_tunnel::update::background_update_check();
}
let server_config = match config.to_server_config() {
Ok(c) => c,
Err(e) => {
eprintln!("Configuration error: {}", e);
std::process::exit(1);
}
};
info!(
"Starting server on {}:{}",
server_config.host, server_config.port
);
serve(server_config).await
}