Skip to content

Commit 40f6bcd

Browse files
authored
Merge pull request #33 from vincenzopalazzo/macros/fix-help-command
server: Handle --help command
2 parents 9e24e8d + e26e467 commit 40f6bcd

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

ldk-server/src/main.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,33 @@ use hyper_util::rt::TokioIo;
1515

1616
use crate::util::config::load_config;
1717
use ldk_node::config::Config;
18+
use std::fs;
1819
use std::path::Path;
1920
use std::sync::Arc;
2021

22+
const USAGE_GUIDE: &str = "Usage: ldk-server <config_path>";
23+
2124
fn main() {
2225
let args: Vec<String> = std::env::args().collect();
2326

2427
if args.len() < 2 {
25-
eprintln!("Usage: {} config_path", args[0]);
28+
eprintln!("{USAGE_GUIDE}");
29+
std::process::exit(-1);
30+
}
31+
32+
let arg = args[1].as_str();
33+
if arg == "-h" || arg == "--help" {
34+
println!("{}", USAGE_GUIDE);
35+
std::process::exit(0);
36+
}
37+
38+
if fs::File::open(arg).is_err() {
39+
eprintln!("Unable to access configuration file.");
2640
std::process::exit(-1);
2741
}
2842

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

3246
ldk_node_config.log_level = LogLevel::Trace;
3347
ldk_node_config.storage_dir_path = config_file.storage_dir_path;

0 commit comments

Comments
 (0)