From 5f2b40ad43eba28ad4d814d0f48d9c105886aaa5 Mon Sep 17 00:00:00 2001 From: Teascade Date: Tue, 17 Apr 2018 00:50:28 +0300 Subject: [PATCH] Add option for new page to not add the page to config.toml --- config.toml | 8 ++++---- src/new_page.rs | 48 +++++++++++++++++++++++++----------------------- src/options.rs | 3 +++ 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/config.toml b/config.toml index 5f9892d..875b5d8 100644 --- a/config.toml +++ b/config.toml @@ -12,10 +12,10 @@ items = ["about", "other", "google"] title = "Google!" link = "https://google.com" -[navbar.item.about] -title = "About" -link = "/" - [navbar.item.other] title = "Other" link = "/other" + +[navbar.item.about] +title = "About" +link = "/" diff --git a/src/new_page.rs b/src/new_page.rs index 65d886d..b55ef3a 100644 --- a/src/new_page.rs +++ b/src/new_page.rs @@ -109,31 +109,33 @@ pub fn generate_new_page(ops: NewOps, logger: &Logger) -> Result<(), Error> { file_writer::write_file(markdown_path, PLACEHOLDER_MARKDOWN, ops.overwrite)?; - logger.log( - LogLevel::INFO, - format!("Adding page config path to config.toml"), - ); - let mut config = GlobalConfigToml::get_config()?; - config - .website - .built_pages - .push(toml_path.to_str().unwrap().to_owned()); + if !ops.no_modify_config { + logger.log( + LogLevel::INFO, + format!("Adding page config path to config.toml"), + ); + let mut config = GlobalConfigToml::get_config()?; + config + .website + .built_pages + .push(toml_path.to_str().unwrap().to_owned()); - logger.log( - LogLevel::DETAIL, - format!("Re-serializing config and writing it"), - ); + logger.log( + LogLevel::DETAIL, + format!("Re-serializing config and writing it"), + ); - match toml::ser::to_string(&config) { - Ok(text) => file_writer::write_file(PathBuf::from("config.toml"), text, ops.overwrite)?, - Err(err) => { - return Err(Error::new( - LogLevel::SEVERE, - format!( - "Failed to serialize config.toml: {}", - err.description().to_owned() - ), - )) + match toml::ser::to_string(&config) { + Ok(text) => file_writer::write_file(PathBuf::from("config.toml"), text, ops.overwrite)?, + Err(err) => { + return Err(Error::new( + LogLevel::SEVERE, + format!( + "Failed to serialize config.toml: {}", + err.description().to_owned() + ), + )) + } } } diff --git a/src/options.rs b/src/options.rs index 1c9b5e4..ad2331a 100644 --- a/src/options.rs +++ b/src/options.rs @@ -50,4 +50,7 @@ pub struct NewOps { /// Overwrites existing .toml / .md files #[structopt(short = "o", long = "overwrite")] pub overwrite: bool, + /// Don't modify config.toml automatically + #[structopt(short = "n", long = "no-modify-config")] + pub no_modify_config: bool, }