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 183cd57
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions ldk-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,29 @@ use ldk_node::config::Config;
use std::path::Path;
use std::sync::Arc;

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

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

if args.len() < 2 {
eprintln!("Usage: {} config_path", args[0]);
eprintln!("{USAGE_GUIDE}");
std::process::exit(-1);
}

let arg = args[1].as_str();
if arg == "-h" || arg == "--help" {
println!("{}", USAGE_GUIDE);
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 183cd57

Please sign in to comment.