Skip to content

Commit 91409d8

Browse files
committed
Add extensive documentation for the 'show' subcommand
This commit adds extensive documentation for the `show` subcommand in the program's reference. It also includes smaller updates and corrections to other parts of the documentation. An in-depth example usage of `show` is added both to the dedicated `show.md` file and in the function's docstring.
1 parent 68f9eee commit 91409d8

File tree

6 files changed

+82
-5
lines changed

6 files changed

+82
-5
lines changed

bumpversion/cli.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,19 @@ def bump(
338338
help="Increment the version part and add `new_version` to the configuration.",
339339
)
340340
def show(args: List[str], config_file: Optional[str], format_: str, increment: Optional[str]) -> None:
341-
"""Show current configuration information."""
341+
"""
342+
Show current configuration information.
343+
344+
ARGS may contain one or more configuration attributes. For example:
345+
346+
- `bump-my-version show current_version`
347+
348+
- `bump-my-version show files.0.filename`
349+
350+
- `bump-my-version show scm_info.branch_name`
351+
352+
- `bump-my-version show current_version scm_info.distance_to_latest_tag`
353+
"""
342354
found_config_file = find_config_file(config_file)
343355
config = get_configuration(found_config_file)
344356

docs/reference/cli.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# CLI Reference
2+
13
::: mkdocs-click
24
:module: bumpversion.cli
35
:command: cli

docs/reference/configuration.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Bump-my-version's default behavior is to abort if the working directory has unco
6868

6969
Whether to create a commit using git or Mercurial.
7070

71-
If you have pre-commit hooks, you might also want to add an option to [`commit_args`](configuration.md#commit-args) to disable your pre-commit hooks. For Git use `--no-verify` and use `--config hooks.pre-commit=` for Mercurial.
71+
If you have pre-commit hooks, you might also want to add an option to [`commit_args`](configuration.md#commit_args) to disable your pre-commit hooks. For Git use `--no-verify` and use `--config hooks.pre-commit=` for Mercurial.
7272

7373
### commit_args
7474

@@ -339,7 +339,7 @@ If `True`, sign the created tag, when [`tag`](configuration.md#tag) is `True`.
339339
environment var
340340
: `BUMPVERSION_TAG`
341341

342-
If `True`, create a tag after committing the changes. The tag is named using the [`tag_name`](configuration.md#tag-name) option.
342+
If `True`, create a tag after committing the changes. The tag is named using the [`tag_name`](configuration.md#tag_name) option.
343343

344344
If you are using `git`, don't forget to `git-push` with the `--tags` flag when you are done.
345345

@@ -533,7 +533,7 @@ When this value is set to `True`, the part is always incremented when the versio
533533
type
534534
: string
535535

536-
The `calver_format` is a string that specifies the format of the version part. It is used to determine the next value when bumping the version. The format is a string that uses the placeholders defined in the [CalVer reference](calver_reference.md#calver-format).
536+
The `calver_format` is a string that specifies the format of the version part. It is used to determine the next value when bumping the version. The format is a string that uses the placeholders defined in the [CalVer reference](calver_reference.md#calver_format).
537537

538538
### Examples
539539

docs/reference/index.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Reference
22

3-
3+
- [Subcommands](subcommands/index.md)
44
- [Command-line interface](cli.md)
55
- [Configuration](configuration.md)
6+
- [Calendar versioning reference](calver_reference.md)
67
- [Formatting context](formatting-context.md)
78
- [Version parts](version-parts.md)
89
- [Search and replace configuration](search-and-replace-config.md)

docs/reference/subcommands/index.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Subcommand reference
2+
3+
Bump-my-version uses subcommands to focus its functionality.
4+
5+
- `bump` triggers the version incrementing workflow
6+
- `replace` replaces the version in files without triggering a version increment.
7+
- `sample-config` helps new users configure bumpy-my-version by printing a sample configuration file.
8+
- `show` provides access to current configuration information.
9+
- `show-bump` helps developers understand the current versioning convention by showing the possible versions resulting from the `bump` subcommand.

docs/reference/subcommands/show.md

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# The show subcommand
2+
3+
The main purpose of the `show` subcommand is to provide access to configuration data via scripts.
4+
5+
## Basic use
6+
7+
The configuration object is a `dict` containing nested data structures. The arguments and options of this command relate to extracting data from the configuration object and presenting the extracted data.
8+
9+
## Specifying the output data
10+
11+
The positional arguments determine the data shown. If nothing or `all` is passed, the entire configuration is shown.
12+
13+
Positional arguments are specified using a format like [Django variable resolution](https://docs.djangoproject.com/en/5.0/ref/templates/language/#variables).
14+
15+
Examples:
16+
17+
- `a.b` specifies the "b" key in the nested dictionaries: `{"a": {"b": "value"}}`
18+
- `a.3` specifies the 4th item (the first is 0) of the list at key "a": `{"a": ["no", "nay", "nyet", "value"]}`
19+
20+
## Specifying the output format
21+
22+
If only one positional argument is passed, the default format only shows its value. If no positional arguments, several positional arguments, or `all` is passed, the output from [`pprint.pprint`](https://docs.python.org/3.12/library/pprint.html#pprint.pprint) is shown.
23+
24+
This makes getting the current version easy:
25+
26+
```console
27+
$ bump-my-version show current_version
28+
1.0.1
29+
```
30+
31+
You can request the output be formatted as YAML or JSON:
32+
33+
```console
34+
$ bump-my-version show --format yaml current_version
35+
current_version: "1.0.1"
36+
$ bump-my-version show --format json current_version
37+
{
38+
"current_version": "1.0.1"
39+
}
40+
```
41+
42+
## Including the incremented version before bumping
43+
44+
Your workflow might want to know the new version before you actually do the bumping. The `--increment` or `-i` option accepts a version part to bump and adds a `new_version` key into the configuration.
45+
46+
```console
47+
$ bump-my-version --increment patch show
48+
1.0.2
49+
$ bump-my-version --increment minor show
50+
1.1.0
51+
$ bump-my-version --increment major show
52+
2.0.0
53+
```

0 commit comments

Comments
 (0)