Skip to content

Commit b6ba2fc

Browse files
committed
Fix #466: CLI pass token for prerelease and build
For the CLI pysemver script, this change introduces a --token option when bumping prereleases or builds.
1 parent cc5b1d3 commit b6ba2fc

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/semver/cli.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,16 @@ def cmd_bump(args: argparse.Namespace) -> str:
4040
# print the help and exit
4141
args.parser.parse_args(["bump", "-h"])
4242

43+
# print(">>> args:", args)
44+
4345
ver = Version.parse(args.version)
4446
# get the respective method and call it
4547
func = getattr(ver, maptable[cast(str, args.bump)])
46-
return str(func())
48+
if args.bump in ("prerelease", "build"):
49+
fargs = {"token": args.token}
50+
else:
51+
fargs = {}
52+
return str(func(**fargs))
4753

4854

4955
def cmd_check(args: argparse.Namespace) -> None:
@@ -108,13 +114,14 @@ def createparser() -> argparse.ArgumentParser:
108114
sb = parser_bump.add_subparsers(title="Bump commands", dest="bump")
109115

110116
# Create subparsers for the bump subparser:
111-
for p in (
112-
sb.add_parser("major", help="Bump the major part of the version"),
113-
sb.add_parser("minor", help="Bump the minor part of the version"),
114-
sb.add_parser("patch", help="Bump the patch part of the version"),
115-
sb.add_parser("prerelease", help="Bump the prerelease part of the version"),
116-
sb.add_parser("build", help="Bump the build part of the version"),
117-
):
117+
maptable = {"prerelease": "rc", "build": "build"}
118+
for item in ("major", "minor", "patch", "prerelease", "build"):
119+
p = sb.add_parser(item, help="Bump the {} part of the version".format(item))
120+
if item in ("prerelease", "build"):
121+
p.add_argument("--token",
122+
default=maptable.get(item),
123+
help="The token to use for {}".format(item))
124+
118125
p.add_argument("version", help="Version to raise")
119126

120127
# Create the check subcommand

0 commit comments

Comments
 (0)