Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit 480bb64

Browse files
committed
fix: better tag support for changelog
1 parent c8a2f7d commit 480bb64

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

sbin/changelog.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,24 @@ def changelog_part(commitish_to: str, commitish_from: str, version: str):
109109
help="Don't include a changelog header",
110110
)
111111

112-
subparsers = parser.add_subparsers(dest="type")
112+
subparsers = parser.add_subparsers(
113+
dest="type", metavar="COMMAND", help='One of "single" or "full".', required=True
114+
)
113115

114116
single = subparsers.add_parser(
115-
"single", description="Changelog for a single release"
117+
"single", description="Generate changelog for a single tag."
116118
)
117-
single.add_argument("-tag", "--tag", type=str, metavar="TAG")
119+
single.add_argument("-t", "--tag", type=str, metavar="TAG")
118120

119-
full = subparsers.add_parser("full")
121+
full = subparsers.add_parser(
122+
"full", description="Generate a changelog covering entire history."
123+
)
120124
full.add_argument(
121-
"-release",
125+
"-r",
122126
"--release",
123127
type=str,
124128
metavar="RELEASE",
125-
help="New relase, includes full changelog with a new entry for things not tagged",
129+
help="New release tag (e.g. vX.Y.Z), includes full changelog with a new entry for things not tagged",
126130
)
127131

128132
args = parser.parse_args()
@@ -139,6 +143,18 @@ def changelog_part(commitish_to: str, commitish_from: str, version: str):
139143
"HEAD",
140144
]
141145
).split()
146+
147+
if args.tag is None:
148+
try:
149+
args.tag = tags[0]
150+
except:
151+
print(f"Error: no tags found!")
152+
sys.exit(1)
153+
154+
if args.type == "single" and args.tag not in tags:
155+
print(f"Error: tag {args.tag} not found!")
156+
sys.exit(1)
157+
142158
if args.type == "full" and args.release is not None:
143159
tags.insert(0, "HEAD")
144160

0 commit comments

Comments
 (0)