Skip to content

Commit 1f0ddc6

Browse files
committed
docs: Improve docs (readme, usage, CLI reference)
1 parent c593557 commit 1f0ddc6

File tree

6 files changed

+245
-224
lines changed

6 files changed

+245
-224
lines changed

README.md

+18-138
Original file line numberDiff line numberDiff line change
@@ -67,144 +67,24 @@ python3.8 -m pip install --user pipx
6767
pipx install git-changelog
6868
```
6969

70-
## Usage (command-line)
70+
## Usage
7171

7272
```
73-
usage: git-changelog [-b] [-h] [-i] [-g VERSION_REGEX] [-m MARKER_LINE]
74-
[-o OUTPUT] [-r] [-R] [-I INPUT]
75-
[-c {angular,conventional,basic}] [-s SECTIONS]
76-
[-t {angular,keepachangelog}] [-T] [-E] [-v]
77-
[REPOSITORY]
78-
79-
Automatic Changelog generator using Jinja2 templates.
80-
81-
This tool parses your commit messages to extract useful data
82-
that is then rendered using Jinja2 templates, for example to
83-
a changelog file formatted in Markdown.
84-
85-
Each Git tag will be treated as a version of your project.
86-
Each version contains a set of commits, and will be an entry
87-
in your changelog. Commits in each version will be grouped
88-
by sections, depending on the commit convention you follow.
89-
90-
BASIC CONVENTION
91-
92-
Default sections:
93-
- add: Added
94-
- fix: Fixed
95-
- change: Changed
96-
- remove: Removed
97-
98-
Additional sections:
99-
- merge: Merged
100-
- doc: Documented
101-
102-
ANGULAR CONVENTION
103-
104-
Default sections:
105-
- feat: Features
106-
- fix: Bug Fixes
107-
- revert: Reverts
108-
- ref, refactor: Code Refactoring
109-
- perf: Performance Improvements
110-
111-
Additional sections:
112-
- build: Build
113-
- chore: Chore
114-
- ci: Continuous Integration
115-
- deps: Dependencies
116-
- doc, docs: Docs
117-
- style: Style
118-
- test, tests: Tests
119-
120-
CONVENTIONALCOMMIT CONVENTION
121-
122-
Default sections:
123-
- feat: Features
124-
- fix: Bug Fixes
125-
- revert: Reverts
126-
- ref, refactor: Code Refactoring
127-
- perf: Performance Improvements
128-
129-
Additional sections:
130-
- build: Build
131-
- chore: Chore
132-
- ci: Continuous Integration
133-
- deps: Dependencies
134-
- doc, docs: Docs
135-
- style: Style
136-
- test, tests: Tests
137-
138-
positional arguments:
139-
REPOSITORY The repository path, relative or absolute. Default: .
140-
141-
options:
142-
-b, --bump-latest Deprecated, use --bump=auto instead.
143-
Guess the new latest version by bumping the previous
144-
one based on the set of unreleased commits. For
145-
example, if a commit contains breaking changes, bump
146-
the major number (or the minor number for 0.x
147-
versions). Else if there are new features, bump the
148-
minor number. Else just bump the patch number.
149-
Default: False.
150-
--bump VERSION Specify the bump from latest version for the set
151-
of unreleased commits. Can be one of 'auto',
152-
'major', 'minor', 'patch' or a valid semver version
153-
(eg. 1.2.3). With 'auto', if a commit contains breaking
154-
changes, bump the major number (or the minor number
155-
for 0.x versions), else if there are new features,
156-
bump the minor number, else just bump the patch number.
157-
Default: None.
158-
-Z, --no-zerover By default, breaking changes on a 0.x don't bump the
159-
major version, maintaining it at 0. With this option, a
160-
breaking change will bump a 0.x version to 1.0.
161-
-h, --help Show this help message and exit.
162-
-i, --in-place Insert new entries (versions missing from changelog)
163-
in-place. An output file must be specified. With
164-
custom templates, you can pass two additional
165-
arguments: --version-regex and --marker-line. When
166-
writing in-place, an 'in_place' variable will be
167-
injected in the Jinja context, allowing to adapt the
168-
generated contents (for example to skip changelog
169-
headers or footers). Default: False.
170-
-g, --version-regex VERSION_REGEX
171-
A regular expression to match versions in the existing
172-
changelog (used to find the latest release) when
173-
writing in-place. The regular expression must be a
174-
Python regex with a 'version' named group. Default:
175-
^## \[(?P<version>v?[^\]]+).
176-
-m, --marker-line MARKER_LINE
177-
A marker line at which to insert new entries (versions
178-
missing from changelog). If two marker lines are
179-
present in the changelog, the contents between those
180-
two lines will be overwritten (useful to update an
181-
'Unreleased' entry for example). Default:
182-
<!-- insertion marker -->.
183-
-o, --output OUTPUT Output to given file. Default: stdout.
184-
-p {github,gitlab}, --provider {github,gitlab}
185-
Explicitly specify the repository provider.
186-
-r, --parse-refs Parse provider-specific references in commit messages
187-
(GitHub/GitLab/Bitbucket issues, PRs, etc.). Default: False.
188-
-R, --release-notes Output release notes to stdout based on the last entry
189-
in the changelog. Default: False.
190-
-I, --input INPUT Read from given file when creating release notes.
191-
Default: CHANGELOG.md.
192-
-c, --style, --commit-style, --convention {angular,conventional,basic}
193-
The commit convention to match against. Default:
194-
basic.
195-
-s, --sections SECTIONS
196-
A comma-separated list of sections to render. See the
197-
available sections for each supported convention in
198-
the description. Default: None.
199-
-t {angular,keepachangelog}, --template {angular,keepachangelog}
200-
The Jinja2 template to use. Prefix with "path:" to
201-
specify the path to a directory containing a file
202-
named "changelog.md". Default: keepachangelog.
203-
-T, --trailers, --git-trailers
204-
Parse Git trailers in the commit message. See
205-
https://git-scm.com/docs/git-interpret-trailers.
206-
Default: False.
207-
-E, --omit-empty-versions
208-
Omit empty versions in the output. Default: False.
209-
-v, --version Show the current version of the program and exit.
73+
git-changelog [--config-file [PATH ...]] [-b] [-B VERSION] [-h] [-i]
74+
[-g VERSION_REGEX] [-m MARKER_LINE] [-o OUTPUT]
75+
[-p {github,gitlab,bitbucket}] [-r] [-R] [-I INPUT]
76+
[-c {angular,conventional,basic}] [-s SECTIONS]
77+
[-t {angular,keepachangelog}] [-T] [-E] [-Z] [-F FILTER_COMMITS]
78+
[-V] [--debug-info]
79+
[REPOSITORY]
21080
```
81+
82+
Simply run `git-changelog` in your repository to output a changelog on standard output.
83+
To show the different options and their descriptions, use `git-changelog -h`.
84+
85+
- See [Quick usage](http://pawamoy.github.io/git-changelog/usage/#quick-usage)
86+
for some command line examples.
87+
- See [Configuration](https://pawamoy.github.io/git-changelog/usage/#configuration-files)
88+
to learn how to configure *git-changelog* for your project.
89+
- See the [CLI reference](https://pawamoy.github.io/git-changelog/cli)
90+
and the [API reference](https://pawamoy.github.io/git-changelog/reference) for more information.

docs/cli.md

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
hide:
3+
- navigation
4+
---
5+
6+
# CLI reference
7+
8+
<style>
9+
.doclink {
10+
display: inline;
11+
position: relative;
12+
top: -8px;
13+
font-size: .65rem;
14+
}
15+
p:has(> a.doclink) {
16+
line-height: 0.2;
17+
}
18+
</style>
19+
20+
```python exec="true" idprefix=""
21+
import argparse
22+
import sys
23+
24+
from git_changelog.cli import get_parser
25+
26+
parser = get_parser()
27+
28+
option_to_docs = {
29+
"bump": "#understand-the-relationship-with-semver",
30+
"bump_latest": "#understand-the-relationship-with-semver",
31+
"config_file": "#configuration-files",
32+
"convention": "#choose-the-commit-message-convention",
33+
"filter_commits": "#filter-commits",
34+
"in_place": "#update-changelog-in-place",
35+
"input": "#output-release-notes",
36+
"marker_line": "#update-changelog-in-place",
37+
"omit_empty_versions": "#",
38+
"output": "#output-a-changelog",
39+
"parse_refs": "#provider-specific-references",
40+
"parse_trailers": "#git-trailers",
41+
"provider": "#provider-specific-references",
42+
"release_notes": "#output-release-notes",
43+
"sections": "#choose-the-sections-to-render",
44+
"template": "#choose-a-changelog-template",
45+
"version_regex": "#update-changelog-in-place",
46+
"zerover": "#understand-the-relationship-with-semver",
47+
}
48+
49+
50+
def render_parser(parser: argparse.ArgumentParser, title: str, heading_level: int = 2) -> str:
51+
"""Render the parser help documents as a string."""
52+
result = [f"{'#' * heading_level} {title}\n"]
53+
if parser.description and title != "pdm":
54+
result.append("> " + parser.description + "\n")
55+
56+
for group in sorted(parser._action_groups, key=lambda g: g.title.lower(), reverse=True):
57+
if not any(
58+
bool(action.option_strings or action.dest) or isinstance(action, argparse._SubParsersAction)
59+
for action in group._group_actions
60+
):
61+
continue
62+
63+
result.append(f"{'#' * (heading_level + 1)} {group.title.title()}\n")
64+
for action in sorted(group._group_actions, key=lambda action: action.dest):
65+
if isinstance(action, argparse._SubParsersAction):
66+
for name, subparser in action._name_parser_map.items():
67+
result.append(render_parser(subparser, name, heading_level + 1))
68+
continue
69+
70+
opts = [f"`{opt}`" for opt in action.option_strings]
71+
docs = ""
72+
if action.dest in option_to_docs:
73+
docs = f"[(docs)](../usage/{option_to_docs[action.dest]}){{ .doclink }}\n\n"
74+
if not opts:
75+
line = f"{'#' * (heading_level + 2)} `{action.dest}`\n\n{docs}- "
76+
else:
77+
line = f"{'#' * (heading_level + 2)} `{action.dest}`\n\n{docs}- {', '.join(opts)}"
78+
if action.metavar:
79+
line += f" `{action.metavar}`"
80+
line += f": {action.help}"
81+
if action.default and action.default != argparse.SUPPRESS:
82+
if action.default is sys.stdout:
83+
default = "sys.stdout"
84+
else:
85+
default = action.default
86+
line += f" Default: `{default}`."
87+
result.append(line)
88+
result.append("")
89+
90+
return "\n".join(result)
91+
92+
93+
print(render_parser(parser, "git-changelog"))
94+
```

0 commit comments

Comments
 (0)