From 222c8bba810cb20eeb60270e89857ab09324884d Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Thu, 10 Aug 2023 11:43:47 +0200 Subject: [PATCH 1/3] daemon bin: a more helpful error message on unknown arguments. --- src/bin/daemon.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/bin/daemon.rs b/src/bin/daemon.rs index 04a4af2d..c12c8780 100644 --- a/src/bin/daemon.rs +++ b/src/bin/daemon.rs @@ -13,8 +13,9 @@ fn parse_args(args: Vec) -> Option { } if args.len() != 3 { - eprintln!("Unknown arguments '{:?}'.", args); - eprintln!("Only '--conf ' is supported."); + eprintln!("A TOML configuration file is required to run lianad. By default lianad looks for a 'config.toml' file in its data directory. A different one may be provided like so: '--conf '."); + eprintln!("A documented example of the configuration file is available at https://github.com/wizardsardine/liana/blob/607c0abddab2ff5761b371c6020b0793b1a1bc97/contrib/lianad_config_example.toml."); + eprintln!("The default data directory path is a 'liana/' folder in the XDG standard configuration directory for all OSes but Linux ones, where it's '~/.liana/'."); process::exit(1); } From 01ce0f179d8ef059f04e56e8f7c125264e9949b1 Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Thu, 10 Aug 2023 11:46:41 +0200 Subject: [PATCH 2/3] daemon bin: more helpful error message on config file parsing error --- src/bin/daemon.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/bin/daemon.rs b/src/bin/daemon.rs index c12c8780..9cb75b62 100644 --- a/src/bin/daemon.rs +++ b/src/bin/daemon.rs @@ -7,16 +7,20 @@ use std::{ use liana::{config::Config, DaemonHandle}; +fn print_help_exit() { + eprintln!("A TOML configuration file is required to run lianad. By default lianad looks for a 'config.toml' file in its data directory. A different one may be provided like so: '--conf '."); + eprintln!("A documented sample is available at https://github.com/wizardsardine/liana/blob/607c0abddab2ff5761b371c6020b0793b1a1bc97/contrib/lianad_config_example.toml."); + eprintln!("The default data directory path is a 'liana/' folder in the XDG standard configuration directory for all OSes but Linux ones, where it's '~/.liana/'."); + process::exit(1); +} + fn parse_args(args: Vec) -> Option { if args.len() == 1 { return None; } if args.len() != 3 { - eprintln!("A TOML configuration file is required to run lianad. By default lianad looks for a 'config.toml' file in its data directory. A different one may be provided like so: '--conf '."); - eprintln!("A documented example of the configuration file is available at https://github.com/wizardsardine/liana/blob/607c0abddab2ff5761b371c6020b0793b1a1bc97/contrib/lianad_config_example.toml."); - eprintln!("The default data directory path is a 'liana/' folder in the XDG standard configuration directory for all OSes but Linux ones, where it's '~/.liana/'."); - process::exit(1); + print_help_exit(); } Some(PathBuf::from(args[2].to_owned())) @@ -53,7 +57,8 @@ fn main() { let config = Config::from_file(conf_file).unwrap_or_else(|e| { eprintln!("Error parsing config: {}", e); - process::exit(1); + print_help_exit(); + unreachable!(); }); setup_logger(config.log_level).unwrap_or_else(|e| { eprintln!("Error setting up logger: {}", e); From d4da2bf6b451de0cd44630c077b83426ed581940 Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Thu, 10 Aug 2023 11:47:55 +0200 Subject: [PATCH 3/3] daemon bin: try to detect '--help' or '-h' It should fall into the "number of args isn't equal to 3" category anyways, but it's a cheap way of trying to be more helpful. --- src/bin/daemon.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bin/daemon.rs b/src/bin/daemon.rs index 9cb75b62..0856cfb7 100644 --- a/src/bin/daemon.rs +++ b/src/bin/daemon.rs @@ -9,7 +9,7 @@ use liana::{config::Config, DaemonHandle}; fn print_help_exit() { eprintln!("A TOML configuration file is required to run lianad. By default lianad looks for a 'config.toml' file in its data directory. A different one may be provided like so: '--conf '."); - eprintln!("A documented sample is available at https://github.com/wizardsardine/liana/blob/607c0abddab2ff5761b371c6020b0793b1a1bc97/contrib/lianad_config_example.toml."); + eprintln!("A documented sample is available at 'contrib/lianad_config_example.toml' in the source tree (https://github.com/wizardsardine/liana/blob/v1.0/contrib/lianad_config_example.toml)."); eprintln!("The default data directory path is a 'liana/' folder in the XDG standard configuration directory for all OSes but Linux ones, where it's '~/.liana/'."); process::exit(1); } @@ -19,7 +19,10 @@ fn parse_args(args: Vec) -> Option { return None; } - if args.len() != 3 { + let is_help = args + .iter() + .any(|arg| arg.contains("help") || arg.contains("-h")); + if args.len() != 3 || is_help { print_help_exit(); }