mirror of
https://github.com/orhun/systeroid
synced 2024-07-21 18:35:03 +00:00
feat(args): add --verbose
flag for logging verbosity
This commit is contained in:
parent
6e2709c332
commit
830535a170
|
@ -60,6 +60,8 @@ impl Default for AppConfig {
|
|||
/// Sysctl configuration.
|
||||
#[derive(Debug, Default)]
|
||||
pub struct SysctlConfig {
|
||||
/// Whether if the verbose logging is enabled.
|
||||
pub verbose: bool,
|
||||
/// Whether if the errors should be ignored.
|
||||
pub ignore_errors: bool,
|
||||
}
|
||||
|
|
|
@ -32,7 +32,9 @@ impl Sysctl {
|
|||
parameters.push(parameter);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("error: `{} ({})`", e, ctl.name()?);
|
||||
if config.verbose {
|
||||
eprintln!("{} ({})", e, ctl.name()?);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ For more details see {bin}(8)."#;
|
|||
/// Command-line arguments.
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Args {
|
||||
/// Whether if the verbose logging is enabled.
|
||||
pub verbose: bool,
|
||||
/// Path of the Linux kernel documentation.
|
||||
pub kernel_docs: Option<PathBuf>,
|
||||
/// Display type of the variables.
|
||||
|
@ -62,7 +64,8 @@ impl Args {
|
|||
"set the path of the kernel documentation",
|
||||
"<path>",
|
||||
);
|
||||
opts.optflag("P", "no-pager", "Do not pipe output into a pager");
|
||||
opts.optflag("P", "no-pager", "do not pipe output into a pager");
|
||||
opts.optflag("v", "verbose", "enable the verbose logging");
|
||||
opts.optflag("h", "help", "display this help and exit");
|
||||
opts.optflag("V", "version", "output version information and exit");
|
||||
|
||||
|
@ -108,6 +111,7 @@ impl Args {
|
|||
DisplayType::Default
|
||||
};
|
||||
Some(Args {
|
||||
verbose: matches.opt_present("v"),
|
||||
kernel_docs: matches.opt_str("d").map(PathBuf::from),
|
||||
display_type,
|
||||
ignore_errors: matches.opt_present("e"),
|
||||
|
|
|
@ -17,6 +17,7 @@ use systeroid_core::sysctl::controller::Sysctl;
|
|||
/// Runs `systeroid`.
|
||||
pub fn run(args: Args) -> Result<()> {
|
||||
let mut config = Config::default();
|
||||
config.sysctl.verbose = args.verbose;
|
||||
config.sysctl.ignore_errors = args.ignore_errors;
|
||||
config.app.display_type = args.display_type;
|
||||
config.app.no_color = env::var("NO_COLOR").is_ok();
|
||||
|
|
Loading…
Reference in a new issue