diff --git a/src/main.rs b/src/main.rs index f4187e2..c62981d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ mod upstreams; use crate::config::ConfigV1; use crate::servers::Server; +use std::io::{stderr, stdout, Write}; use log::{debug, error, info}; use pico_args::Arguments; @@ -16,17 +17,35 @@ fn main() { match args.subcommand().expect("Unexpected error").as_deref() { Some("serve") => serve(), Some("update") => update::update(), + Some("help") => { + let _ = print_usage(&mut stdout().lock()); + } Some(cmd) => { eprintln!("Invalid command: {cmd}"); std::process::exit(1); } None => { eprintln!("Calling l4p without argument is deprecated now. Please use: l4p serve"); + let _ = print_usage(&mut stderr().lock()); serve(); } } } +fn print_usage(out: &mut dyn Write) -> std::io::Result<()> { + writeln!( + out, + "{} v{}", + env!("CARGO_PKG_NAME"), + env!("CARGO_PKG_VERSION") + )?; + writeln!(out, "Usage:")?; + writeln!(out, "\tupdate\tUpdate l4p to the latest version")?; + writeln!(out, "\tserve\tServe the proxy")?; + writeln!(out, "\thelp\tPrint this message")?; + Ok(()) +} + fn serve() { let config_path = match find_config() { Ok(p) => p,