Add help to main command
Signed-off-by: Jacob Kiers <code@kiers.eu>
This commit is contained in:
parent
6300c43495
commit
922ea1f030
19
src/main.rs
19
src/main.rs
@ -5,6 +5,7 @@ mod upstreams;
|
|||||||
|
|
||||||
use crate::config::ConfigV1;
|
use crate::config::ConfigV1;
|
||||||
use crate::servers::Server;
|
use crate::servers::Server;
|
||||||
|
use std::io::{stderr, stdout, Write};
|
||||||
|
|
||||||
use log::{debug, error, info};
|
use log::{debug, error, info};
|
||||||
use pico_args::Arguments;
|
use pico_args::Arguments;
|
||||||
@ -16,17 +17,35 @@ fn main() {
|
|||||||
match args.subcommand().expect("Unexpected error").as_deref() {
|
match args.subcommand().expect("Unexpected error").as_deref() {
|
||||||
Some("serve") => serve(),
|
Some("serve") => serve(),
|
||||||
Some("update") => update::update(),
|
Some("update") => update::update(),
|
||||||
|
Some("help") => {
|
||||||
|
let _ = print_usage(&mut stdout().lock());
|
||||||
|
}
|
||||||
Some(cmd) => {
|
Some(cmd) => {
|
||||||
eprintln!("Invalid command: {cmd}");
|
eprintln!("Invalid command: {cmd}");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
eprintln!("Calling l4p without argument is deprecated now. Please use: l4p serve");
|
eprintln!("Calling l4p without argument is deprecated now. Please use: l4p serve");
|
||||||
|
let _ = print_usage(&mut stderr().lock());
|
||||||
serve();
|
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() {
|
fn serve() {
|
||||||
let config_path = match find_config() {
|
let config_path = match find_config() {
|
||||||
Ok(p) => p,
|
Ok(p) => p,
|
||||||
|
Loading…
Reference in New Issue
Block a user