Skip to main content

git_harvest/
cli.rs

1/*********************** GNU General Public License 3.0 ***********************\
2|                                                                              |
3|  Copyright (C) 2026 Kevin Matthes                                            |
4|                                                                              |
5|  This program is free software: you can redistribute it and/or modify        |
6|  it under the terms of the GNU General Public License as published by        |
7|  the Free Software Foundation, either version 3 of the License, or           |
8|  (at your option) any later version.                                         |
9|                                                                              |
10|  This program is distributed in the hope that it will be useful,             |
11|  but WITHOUT ANY WARRANTY; without even the implied warranty of              |
12|  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
13|  GNU General Public License for more details.                                |
14|                                                                              |
15|  You should have received a copy of the GNU General Public License           |
16|  along with this program.  If not, see <https://www.gnu.org/licenses/>.      |
17|                                                                              |
18\******************************************************************************/
19
20//! The command line surface of `git-harvest`.
21
22/// Harvest a CHANGELOG from a repository's Git history.
23#[derive(clap::Parser, Debug)]
24#[command(about, version)]
25pub struct Cli {
26    /// The task to run.
27    #[command(subcommand)]
28    pub command: Command,
29}
30
31/// The tasks `git-harvest` can perform.
32#[derive(clap::Subcommand, Debug)]
33pub enum Command {
34    /// Merge the harvested fragments into a new CHANGELOG section.
35    Assemble(AssembleArguments),
36
37    /// Write a fresh CHANGELOG carrying the default configuration.
38    Init(InitArguments),
39
40    /// Render the CHANGELOG as a Keep a Changelog Markdown file.
41    Render(RenderArguments),
42
43    /// Harvest this branch's structured commits into a fragment.
44    Scan(ScanArguments),
45}
46
47/// The arguments of `git-harvest assemble`.
48#[derive(clap::Args, Debug)]
49pub struct AssembleArguments {
50    /// The CHANGELOG to merge the fragments into.
51    #[arg(default_value = "CHANGELOG.ron", long, short)]
52    pub changelog: std::path::PathBuf,
53
54    /// The directory the fragments are read from and then cleared.
55    #[arg(default_value = "changelog.d", long, short)]
56    pub input: std::path::PathBuf,
57
58    /// The publish moment, RFC 3339; defaults to now, in UTC.
59    #[arg(long, short)]
60    pub released: Option<String>,
61
62    /// The version the new section documents, as `major.minor.patch`.
63    pub version: String,
64}
65
66/// The arguments of `git-harvest init`.
67#[derive(clap::Args, Debug)]
68pub struct InitArguments {
69    /// The path to write the CHANGELOG to.
70    #[arg(default_value = "CHANGELOG.ron", long, short)]
71    pub output: std::path::PathBuf,
72
73    /// Overwrite the target when it exists already.
74    #[arg(long, short)]
75    pub force: bool,
76}
77
78/// The arguments of `git-harvest render`.
79#[derive(clap::Args, Debug)]
80pub struct RenderArguments {
81    /// The CHANGELOG to read.
82    #[arg(default_value = "CHANGELOG.ron", long, short)]
83    pub changelog: std::path::PathBuf,
84
85    /// The Markdown file to write; it is always overwritten.
86    #[arg(default_value = "CHANGELOG.md", long, short)]
87    pub output: std::path::PathBuf,
88}
89
90/// The arguments of `git-harvest scan`.
91#[derive(clap::Args, Debug)]
92pub struct ScanArguments {
93    /// The ref the branch diverged from; its merge base bounds the walk.
94    #[arg(default_value = "main", long, short)]
95    pub base: String,
96
97    /// The CHANGELOG to read the harvest configuration from, if it exists.
98    #[arg(default_value = "CHANGELOG.ron", long, short)]
99    pub changelog: std::path::PathBuf,
100
101    /// Overwrite the fragment when one of the same name exists already.
102    #[arg(long, short)]
103    pub force: bool,
104
105    /// The directory to write the fragment into.
106    #[arg(default_value = "changelog.d", long, short)]
107    pub output: std::path::PathBuf,
108}
109
110/******************************************************************************/