Skip to content

Commit 04b5846

Browse files
committed
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
1 parent 5951139 commit 04b5846

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

bin/gen/src/subcommand.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ pub(crate) enum Subcommand {
1212
no_git: bool,
1313
},
1414
#[structopt(about("Generate book"))]
15-
Book,
15+
Book {
16+
#[structopt(
17+
long = "no-git",
18+
help = "Skip book contents require a Git repository. Currently this only includes the \
19+
changelog."
20+
)]
21+
no_git: bool,
22+
},
1623
#[structopt(about("Generate the changelog"))]
1724
Changelog,
1825
#[structopt(about("Print a commit template to standard output"))]
@@ -77,7 +84,7 @@ impl Subcommand {
7784
}
7885
Self::CompletionScripts => Self::completion_scripts(&project)?,
7986
Self::Readme => Self::readme(&project)?,
80-
Self::Book => Self::book(&project)?,
87+
Self::Book { no_git } => Self::book(&project, no_git)?,
8188
Self::Man => Self::man(&project)?,
8289
Self::Diff => Self::diff(&project)?,
8390
Self::All { no_git } => Self::all(&project, no_git)?,
@@ -91,7 +98,7 @@ impl Subcommand {
9198
}
9299
Self::completion_scripts(&project)?;
93100
Self::readme(&project)?;
94-
Self::book(&project)?;
101+
Self::book(&project, no_git)?;
95102
Self::man(&project)?;
96103
}
97104

@@ -188,7 +195,7 @@ impl Subcommand {
188195
}
189196

190197
#[throws]
191-
pub(crate) fn book(project: &Project) {
198+
pub(crate) fn book(project: &Project, no_git: bool) {
192199
info!("Generating book…");
193200

194201
let gen = project.gen()?;
@@ -221,14 +228,17 @@ impl Subcommand {
221228

222229
Faq::new(&project.config.faq).render_to(out.join("faq.md"))?;
223230

224-
Summary::new(project).render_to(out.join("SUMMARY.md"))?;
225-
226231
Introduction::new(&project.config).render_to(out.join("introduction.md"))?;
227232

228-
let changelog = Changelog::new(&project)?;
233+
let include_changelog = !no_git;
234+
235+
Summary::new(project, include_changelog).render_to(out.join("SUMMARY.md"))?;
229236

230-
let dst = out.join("changelog.md");
231-
fs::write(&dst, changelog.render(true)?).context(error::Filesystem { path: dst })?;
237+
if !no_git {
238+
let changelog = Changelog::new(&project)?;
239+
let dst = out.join("changelog.md");
240+
fs::write(&dst, changelog.render(true)?).context(error::Filesystem { path: dst })?;
241+
}
232242
}
233243

234244
#[throws]

bin/gen/src/summary.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ use crate::common::*;
55
pub(crate) struct Summary {
66
pub(crate) commands: String,
77
pub(crate) references: String,
8+
pub(crate) include_changelog: bool,
89
}
910

1011
impl Summary {
11-
pub(crate) fn new(project: &Project) -> Summary {
12+
pub(crate) fn new(project: &Project, include_changelog: bool) -> Summary {
1213
let mut commands = Index::new("Commands", "./commands.md");
1314

1415
for subcommand in &project.bin.subcommands {
@@ -27,6 +28,7 @@ impl Summary {
2728
Summary {
2829
commands: commands.text(),
2930
references: references.text(),
31+
include_changelog,
3032
}
3133
}
3234
}

bin/gen/templates/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ Summary
55

66
- [FAQ](./faq.md)
77

8+
{% if include_changelog %}
89
- [Changelog](./changelog.md)
10+
{% endif %}
911

1012
{{commands}}
1113

0 commit comments

Comments
 (0)