add --release-num cli flag

This commit is contained in:
Manuel Barkhau 2020-09-24 20:34:03 +00:00
parent ada75ade8a
commit b7cb2855f0
5 changed files with 45 additions and 24 deletions

View file

@ -85,14 +85,19 @@ def cli(verbose: int = 0) -> None:
@click.argument("pattern", default="{pycalver}")
@click.option('-v', '--verbose', count=True, help="Control log level. -vv for debug level.")
@click.option(
"--release", default=None, metavar="<name>", help="Override release name of current_version"
"--release",
default=None,
metavar="<name>",
help=(
f"Override release name of current_version. Valid options are: "
f"{', '.join(VALID_RELEASE_VALUES)}."
),
)
@click.option("--major", is_flag=True, default=False, help="Increment major component.")
@click.option("--minor", is_flag=True, default=False, help="Increment minor component.")
@click.option("--patch", is_flag=True, default=False, help="Increment patch component.")
@click.option(
"-p", "--pin-date", is_flag=True, default=False, help="Leave date components unchanged."
)
@click.option("-m", "--minor", is_flag=True, default=False, help="Increment minor component.")
@click.option("-p", "--patch", is_flag=True, default=False, help="Increment patch component.")
@click.option("-r", "--release-num", is_flag=True, default=False, help="Increment release number.")
@click.option("--pin-date", is_flag=True, default=False, help="Leave date components unchanged.")
def test(
old_version: str,
pattern : str = "{pycalver}",
@ -101,6 +106,7 @@ def test(
major : bool = False,
minor : bool = False,
patch : bool = False,
release_num: bool = False,
pin_date : bool = False,
) -> None:
"""Increment a version number for demo purposes."""
@ -117,6 +123,7 @@ def test(
major=major,
minor=minor,
patch=patch,
release_num=release_num,
pin_date=pin_date,
)
if new_version is None:
@ -193,6 +200,7 @@ def _incr(
major : bool = False,
minor : bool = False,
patch : bool = False,
release_num: bool = False,
pin_date: bool = False,
) -> typ.Optional[str]:
v1_parts = list(v1patterns.PART_PATTERNS) + list(v1patterns.FULL_PART_FORMATS)
@ -205,6 +213,7 @@ def _incr(
major=major,
minor=minor,
patch=patch,
release_num=release_num,
pin_date=pin_date,
)
else:
@ -215,6 +224,7 @@ def _incr(
major=major,
minor=minor,
patch=patch,
release_num=release_num,
pin_date=pin_date,
)
@ -346,11 +356,10 @@ def _update_cfg_from_vcs(cfg: config.Config, fetch: bool) -> config.Config:
),
)
@click.option("--major", is_flag=True, default=False, help="Increment major component.")
@click.option("--minor", is_flag=True, default=False, help="Increment minor component.")
@click.option("--patch", is_flag=True, default=False, help="Increment patch component.")
@click.option(
"-p", "--pin-date", is_flag=True, default=False, help="Leave date components unchanged."
)
@click.option("-m", "--minor", is_flag=True, default=False, help="Increment minor component.")
@click.option("-p", "--patch", is_flag=True, default=False, help="Increment patch component.")
@click.option("-r", "--release-num", is_flag=True, default=False, help="Increment release number.")
@click.option("--pin-date", is_flag=True, default=False, help="Leave date components unchanged.")
def bump(
release : typ.Optional[str] = None,
verbose : int = 0,
@ -360,6 +369,7 @@ def bump(
major : bool = False,
minor : bool = False,
patch : bool = False,
release_num: bool = False,
pin_date : bool = False,
) -> None:
"""Increment the current version string and update project files."""
@ -386,6 +396,7 @@ def bump(
major=major,
minor=minor,
patch=patch,
release_num=release_num,
pin_date=pin_date,
)

View file

@ -378,6 +378,7 @@ def incr(
major : bool = False,
minor : bool = False,
patch : bool = False,
release_num: bool = False,
pin_date: bool = False,
) -> typ.Optional[str]:
"""Increment version string.
@ -400,14 +401,16 @@ def incr(
cur_vinfo = cur_vinfo._replace(bid=lexid.next_id(cur_vinfo.bid))
if release:
cur_vinfo = cur_vinfo._replace(tag=release)
if major:
cur_vinfo = cur_vinfo._replace(major=cur_vinfo.major + 1, minor=0, patch=0)
if minor:
cur_vinfo = cur_vinfo._replace(minor=cur_vinfo.minor + 1, patch=0)
if patch:
cur_vinfo = cur_vinfo._replace(patch=cur_vinfo.patch + 1)
if release_num:
cur_vinfo = cur_vinfo._replace(num=cur_vinfo.num + 1)
if release:
cur_vinfo = cur_vinfo._replace(tag=release)
new_version = format_version(cur_vinfo, raw_pattern)
if new_version == old_version:

View file

@ -519,6 +519,7 @@ def incr(
major : bool = False,
minor : bool = False,
patch : bool = False,
release_num: bool = False,
pin_date: bool = False,
) -> typ.Optional[str]:
"""Increment version string.
@ -545,14 +546,18 @@ def incr(
cur_vinfo = cur_vinfo._replace(bid=lexid.next_id(cur_vinfo.bid))
if release:
cur_vinfo = cur_vinfo._replace(tag=release)
if major:
cur_vinfo = cur_vinfo._replace(major=cur_vinfo.major + 1, minor=0, patch=0)
if minor:
cur_vinfo = cur_vinfo._replace(minor=cur_vinfo.minor + 1, patch=0)
if patch:
cur_vinfo = cur_vinfo._replace(patch=cur_vinfo.patch + 1)
if release_num:
cur_vinfo = cur_vinfo._replace(num=cur_vinfo.num + 1)
if release:
if release != cur_vinfo.tag:
cur_vinfo = cur_vinfo._replace(num=0)
cur_vinfo = cur_vinfo._replace(tag=release)
# TODO (mb 2020-09-20): New Rollover Behaviour:
# Reset major, minor, patch to zero if any part to the left of it is incremented