Skip to content

Commit

Permalink
server: do not panic on --help command
Browse files Browse the repository at this point in the history
This commit is including a simple check and suggest a help string
for the user when the command `--help` is used. Without this diff
applied the server will panic and the user will not have any clue
why.

     Running `target/debug/ldk-server --help`
thread 'main' panicked at ldk-server/src/main.rs:30:56:
Invalid configuration file.: Custom { kind: NotFound, error: "Failed to read config file '--help': No such file or directory (os error 2)" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[1]    750067 IOT instruction (core dumped)  cargo run --bin ldk-server -- --help

Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed Dec 10, 2024
1 parent 9e24e8d commit 5b2723a
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion ldk-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ use ldk_node::config::Config;
use std::path::Path;
use std::sync::Arc;

const HELP: &str = r#"
Usage
ldk-server [<option> ...] <config_path>
Options
-h | --help Print help
"#;

fn main() {
let args: Vec<String> = std::env::args().collect();

Expand All @@ -26,8 +36,17 @@ fn main() {
std::process::exit(-1);
}

let arg = args[1].as_str();
match arg {
"-h" | "--help" => {
println!("{}", HELP);
std::process::exit(0);
},
_ => {},
}

let mut ldk_node_config = Config::default();
let config_file = load_config(Path::new(&args[1])).expect("Invalid configuration file.");
let config_file = load_config(Path::new(arg)).expect("Invalid configuration file.");

ldk_node_config.log_level = LogLevel::Trace;
ldk_node_config.storage_dir_path = config_file.storage_dir_path;
Expand Down

0 comments on commit 5b2723a

Please sign in to comment.