From 04b58464c98c5638bdac3f77dbaf666bccbfaea6 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 24 Jun 2020 03:32:48 -0700 Subject: [PATCH] Add `--no-git` flag to `gen book` Skip generating the changelog for the book when `--no-git` is passed to `gen book` or `gen all`. type: added --- bin/gen/src/subcommand.rs | 28 +++++++++++++++++++--------- bin/gen/src/summary.rs | 4 +++- bin/gen/templates/SUMMARY.md | 2 ++ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/bin/gen/src/subcommand.rs b/bin/gen/src/subcommand.rs index 2e5839b..e540e00 100644 --- a/bin/gen/src/subcommand.rs +++ b/bin/gen/src/subcommand.rs @@ -12,7 +12,14 @@ pub(crate) enum Subcommand { no_git: bool, }, #[structopt(about("Generate book"))] - Book, + Book { + #[structopt( + long = "no-git", + help = "Skip book contents require a Git repository. Currently this only includes the \ + changelog." + )] + no_git: bool, + }, #[structopt(about("Generate the changelog"))] Changelog, #[structopt(about("Print a commit template to standard output"))] @@ -77,7 +84,7 @@ impl Subcommand { } Self::CompletionScripts => Self::completion_scripts(&project)?, Self::Readme => Self::readme(&project)?, - Self::Book => Self::book(&project)?, + Self::Book { no_git } => Self::book(&project, no_git)?, Self::Man => Self::man(&project)?, Self::Diff => Self::diff(&project)?, Self::All { no_git } => Self::all(&project, no_git)?, @@ -91,7 +98,7 @@ impl Subcommand { } Self::completion_scripts(&project)?; Self::readme(&project)?; - Self::book(&project)?; + Self::book(&project, no_git)?; Self::man(&project)?; } @@ -188,7 +195,7 @@ impl Subcommand { } #[throws] - pub(crate) fn book(project: &Project) { + pub(crate) fn book(project: &Project, no_git: bool) { info!("Generating book…"); let gen = project.gen()?; @@ -221,14 +228,17 @@ impl Subcommand { Faq::new(&project.config.faq).render_to(out.join("faq.md"))?; - Summary::new(project).render_to(out.join("SUMMARY.md"))?; - Introduction::new(&project.config).render_to(out.join("introduction.md"))?; - let changelog = Changelog::new(&project)?; + let include_changelog = !no_git; - let dst = out.join("changelog.md"); - fs::write(&dst, changelog.render(true)?).context(error::Filesystem { path: dst })?; + Summary::new(project, include_changelog).render_to(out.join("SUMMARY.md"))?; + + if !no_git { + let changelog = Changelog::new(&project)?; + let dst = out.join("changelog.md"); + fs::write(&dst, changelog.render(true)?).context(error::Filesystem { path: dst })?; + } } #[throws] diff --git a/bin/gen/src/summary.rs b/bin/gen/src/summary.rs index 86ea94a..3bec283 100644 --- a/bin/gen/src/summary.rs +++ b/bin/gen/src/summary.rs @@ -5,10 +5,11 @@ use crate::common::*; pub(crate) struct Summary { pub(crate) commands: String, pub(crate) references: String, + pub(crate) include_changelog: bool, } impl Summary { - pub(crate) fn new(project: &Project) -> Summary { + pub(crate) fn new(project: &Project, include_changelog: bool) -> Summary { let mut commands = Index::new("Commands", "./commands.md"); for subcommand in &project.bin.subcommands { @@ -27,6 +28,7 @@ impl Summary { Summary { commands: commands.text(), references: references.text(), + include_changelog, } } } diff --git a/bin/gen/templates/SUMMARY.md b/bin/gen/templates/SUMMARY.md index da78356..1cc68cb 100644 --- a/bin/gen/templates/SUMMARY.md +++ b/bin/gen/templates/SUMMARY.md @@ -5,7 +5,9 @@ Summary - [FAQ](./faq.md) +{% if include_changelog %} - [Changelog](./changelog.md) +{% endif %} {{commands}}