Add a command for showing config reference

This commit is contained in:
Roey Darwish Dror
2020-06-30 10:01:22 +03:00
parent e38252d95d
commit e542054229
2 changed files with 16 additions and 1 deletions

View File

@@ -13,6 +13,8 @@ use structopt::StructOpt;
use strum::{EnumIter, EnumString, EnumVariantNames, IntoEnumIterator, VariantNames}; use strum::{EnumIter, EnumString, EnumVariantNames, IntoEnumIterator, VariantNames};
use which_crate::which; use which_crate::which;
pub static EXAMPLE_CONFIG: &str = include_str!("../config.example.toml");
#[allow(unused_macros)] #[allow(unused_macros)]
macro_rules! str_value { macro_rules! str_value {
($section:ident, $value:ident) => { ($section:ident, $value:ident) => {
@@ -195,7 +197,7 @@ impl ConfigFile {
if !config_path.exists() { if !config_path.exists() {
debug!("No configuration exists"); debug!("No configuration exists");
write(&config_path, include_str!("../config.example.toml")).map_err(|e| { write(&config_path, EXAMPLE_CONFIG).map_err(|e| {
debug!( debug!(
"Unable to write the example configuration file to {}: {}. Using blank config.", "Unable to write the example configuration file to {}: {}. Using blank config.",
config_path.display(), config_path.display(),
@@ -275,6 +277,10 @@ pub struct CommandLineArgs {
#[structopt(long = "edit-config")] #[structopt(long = "edit-config")]
edit_config: bool, edit_config: bool,
/// Show config reference
#[structopt(long = "config-reference")]
show_config_reference: bool,
/// Run inside tmux /// Run inside tmux
#[structopt(short = "t", long = "tmux")] #[structopt(short = "t", long = "tmux")]
run_in_tmux: bool, run_in_tmux: bool,
@@ -324,6 +330,10 @@ impl CommandLineArgs {
pub fn edit_config(&self) -> bool { pub fn edit_config(&self) -> bool {
self.edit_config self.edit_config
} }
pub fn show_config_reference(&self) -> bool {
self.show_config_reference
}
} }
/// Represents the application configuration /// Represents the application configuration

View File

@@ -38,6 +38,11 @@ fn run() -> Result<()> {
return Ok(()); return Ok(());
}; };
if opt.show_config_reference() {
print!("{}", crate::config::EXAMPLE_CONFIG);
return Ok(());
}
let config = Config::load(&base_dirs, opt)?; let config = Config::load(&base_dirs, opt)?;
terminal::set_title(config.set_title()); terminal::set_title(config.set_title());
terminal::set_desktop_notifications(config.notify_each_step()); terminal::set_desktop_notifications(config.notify_each_step());