mirror of
https://github.com/TECHNOFAB11/bumpver.git
synced 2025-12-13 06:50:08 +01:00
Add environment output option (#152)
Add --env option for environment output
This commit is contained in:
parent
b337765114
commit
140ac2e79b
3 changed files with 47 additions and 4 deletions
17
README.md
17
README.md
|
|
@ -538,7 +538,7 @@ ERROR - No patterns matched for file 'src/mymodule/utils.py'
|
||||||
$ bumpver --help
|
$ bumpver --help
|
||||||
Usage: bumpver [OPTIONS] COMMAND [ARGS]...
|
Usage: bumpver [OPTIONS] COMMAND [ARGS]...
|
||||||
|
|
||||||
Automatically update CalVer version strings in plaintext files.
|
Automatically update version strings in plaintext files.
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
--version Show the version and exit.
|
--version Show the version and exit.
|
||||||
|
|
@ -591,6 +591,21 @@ Options:
|
||||||
|
|
||||||
<!-- END bumpver update --help -->
|
<!-- END bumpver update --help -->
|
||||||
|
|
||||||
|
To help with shell script automation, you can use `bumpver show --env`.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ bumpver show -n --env
|
||||||
|
YEAR_Y=2020
|
||||||
|
YEAR_G=
|
||||||
|
...
|
||||||
|
TAG=final
|
||||||
|
...
|
||||||
|
|
||||||
|
$ eval $(bumpver show -n --env)
|
||||||
|
$ echo $TAG
|
||||||
|
final
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### Part Overview
|
### Part Overview
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -189,6 +189,15 @@ fetch_option = click.option(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
env_option = click.option(
|
||||||
|
"-e",
|
||||||
|
"--env",
|
||||||
|
is_flag=True,
|
||||||
|
default=False,
|
||||||
|
help="Print version state for use with shell scripts: eval $(bumpver show --env)",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def version_options(function: typ.Callable) -> typ.Callable:
|
def version_options(function: typ.Callable) -> typ.Callable:
|
||||||
decorators = [
|
decorators = [
|
||||||
click.option("--major", is_flag=True, default=False, help="Increment major component."),
|
click.option("--major", is_flag=True, default=False, help="Increment major component."),
|
||||||
|
|
@ -413,7 +422,8 @@ def grep(
|
||||||
@cli.command()
|
@cli.command()
|
||||||
@verbose_option
|
@verbose_option
|
||||||
@fetch_option
|
@fetch_option
|
||||||
def show(verbose: int = 0, fetch: bool = True) -> None:
|
@env_option
|
||||||
|
def show(verbose: int = 0, fetch: bool = True, env: bool = False) -> None:
|
||||||
"""Show current version of your project."""
|
"""Show current version of your project."""
|
||||||
_configure_logging(verbose=max(_VERBOSE, verbose))
|
_configure_logging(verbose=max(_VERBOSE, verbose))
|
||||||
|
|
||||||
|
|
@ -424,6 +434,13 @@ def show(verbose: int = 0, fetch: bool = True) -> None:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
cfg = _update_cfg_from_vcs(cfg, fetch)
|
cfg = _update_cfg_from_vcs(cfg, fetch)
|
||||||
|
if env:
|
||||||
|
version_info = v2version.parse_version_info(cfg.current_version, cfg.version_pattern)
|
||||||
|
for key, val in version_info._asdict().items():
|
||||||
|
click.echo(f"{key.upper()}={val if val else ''}")
|
||||||
|
click.echo(f"CURRENT_VERSION={cfg.current_version}")
|
||||||
|
click.echo(f"PEP440_VERSION={cfg.pep440_version}")
|
||||||
|
else:
|
||||||
click.echo(f"Current Version: {cfg.current_version}")
|
click.echo(f"Current Version: {cfg.current_version}")
|
||||||
click.echo(f"PEP440 : {cfg.pep440_version}")
|
click.echo(f"PEP440 : {cfg.pep440_version}")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -116,6 +116,17 @@ def test_version(runner):
|
||||||
assert match
|
assert match
|
||||||
|
|
||||||
|
|
||||||
|
def test_show_env(runner):
|
||||||
|
_add_project_files("README.md", "setup.cfg")
|
||||||
|
|
||||||
|
result = runner.invoke(cli.cli, ['init', "-vv"])
|
||||||
|
assert result.exit_code == 0
|
||||||
|
|
||||||
|
result = runner.invoke(cli.cli, ['show', "-e"])
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert "TAG=alpha" in result.output
|
||||||
|
|
||||||
|
|
||||||
def test_incr_default(runner):
|
def test_incr_default(runner):
|
||||||
old_version = "v201709.1004-alpha"
|
old_version = "v201709.1004-alpha"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue