-
Notifications
You must be signed in to change notification settings - Fork 26
Add CLI args and env var support #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ use std::path::{Path, PathBuf}; | |
| use std::sync::Arc; | ||
| use std::time::{SystemTime, UNIX_EPOCH}; | ||
|
|
||
| use clap::Parser; | ||
| use hex::DisplayHex; | ||
| use hyper::server::conn::http1; | ||
| use hyper_util::rt::TokioIo; | ||
|
|
@@ -48,15 +49,14 @@ use crate::io::persist::{ | |
| PAYMENTS_PERSISTENCE_SECONDARY_NAMESPACE, | ||
| }; | ||
| use crate::service::NodeService; | ||
| use crate::util::config::{load_config, ChainSource}; | ||
| use crate::util::config::{load_config, ArgsConfig, ChainSource}; | ||
| use crate::util::logger::ServerLogger; | ||
| use crate::util::proto_adapter::{forwarded_payment_to_proto, payment_to_proto}; | ||
| use crate::util::tls::get_or_generate_tls_config; | ||
|
|
||
| const DEFAULT_CONFIG_FILE: &str = "config.toml"; | ||
| const API_KEY_FILE: &str = "api_key"; | ||
|
|
||
| fn get_default_data_dir() -> Option<PathBuf> { | ||
| pub fn get_default_data_dir() -> Option<PathBuf> { | ||
| #[cfg(target_os = "macos")] | ||
| { | ||
| #[allow(deprecated)] // todo can remove once we update MSRV to 1.87+ | ||
|
|
@@ -73,48 +73,14 @@ fn get_default_data_dir() -> Option<PathBuf> { | |
| } | ||
| } | ||
|
|
||
| fn get_default_config_path() -> Option<PathBuf> { | ||
| get_default_data_dir().map(|data_dir| data_dir.join(DEFAULT_CONFIG_FILE)) | ||
| } | ||
|
|
||
| const USAGE_GUIDE: &str = "Usage: ldk-server [config_path] | ||
|
|
||
| If no config path is provided, ldk-server will look for a config file at: | ||
| Linux: ~/.ldk-server/config.toml | ||
| macOS: ~/Library/Application Support/ldk-server/config.toml | ||
| Windows: %APPDATA%\\ldk-server\\config.toml"; | ||
|
|
||
| fn main() { | ||
| let args: Vec<String> = std::env::args().collect(); | ||
|
|
||
| let config_path: PathBuf = if args.len() < 2 { | ||
| match get_default_config_path() { | ||
| Some(path) => path, | ||
| None => { | ||
| eprintln!("Unable to determine home directory for default config path."); | ||
| eprintln!("{USAGE_GUIDE}"); | ||
| std::process::exit(-1); | ||
| }, | ||
| } | ||
| } else { | ||
| let arg = args[1].as_str(); | ||
| if arg == "-h" || arg == "--help" { | ||
| println!("{USAGE_GUIDE}"); | ||
| std::process::exit(0); | ||
| } | ||
| PathBuf::from(arg) | ||
| }; | ||
|
|
||
| if fs::File::open(&config_path).is_err() { | ||
| eprintln!("Unable to access configuration file: {}", config_path.display()); | ||
| std::process::exit(-1); | ||
| } | ||
| let args_config = ArgsConfig::parse(); | ||
|
|
||
| let mut ldk_node_config = Config::default(); | ||
| let config_file = match load_config(&config_path) { | ||
| let config_file = match load_config(&args_config) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Config path and the args above is never used now. We should be able to remove that logic as we use clap now, but we still should check for the default config file
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| Ok(config) => config, | ||
| Err(e) => { | ||
| eprintln!("Invalid configuration file: {}", e); | ||
| eprintln!("Invalid configuration: {e}"); | ||
| std::process::exit(-1); | ||
| }, | ||
| }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this is only used in config can we move this function there now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is also used for
storage_dirinmain