hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit f1be30f83c4d544589ef693dac08b88abd5872d3
parent a43f1f8618c6fa4ca5fc07bb20cf09b6dfe748bc
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon, 22 Nov 2021 09:23:07 +0100

hare release: allow setting tag name manually

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mcmd/hare/release.ha | 34+++++++++++++++++++++++++---------
Mcmd/hare/subcmds.ha | 14+++++++++-----
2 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/cmd/hare/release.ha b/cmd/hare/release.ha @@ -56,7 +56,10 @@ fn parseversion(in: str) (modversion | badversion) = { return (major, minor, patch); }; -fn do_release(incr: increment, dryrun: bool) (void | release_error) = { +fn do_release( + next: (increment | modversion), + dryrun: bool, +) (void | release_error) = { // XXX: If we were feeling REALLY fancy we could run the diff and // automatically detect new functions/types/etc (minor bump), breaking // changes (major bump), or neither (patch bump). I don't feel that @@ -83,14 +86,7 @@ fn do_release(incr: increment, dryrun: bool) (void | release_error) = { defer free(lasttag); const current = parseversion(lasttag)?; - const new: modversion = switch (incr) { - case increment::MAJOR => - yield (current.0 + 1, 0, 0); - case increment::MINOR => - yield (current.0, current.1 + 1, 0); - case increment::PATCH => - yield (current.0, current.1, current.2 + 1); - }; + const new = nextversion(current, next); const newtag = fmt::asprintf("{}.{}.{}", new.0, new.1, new.2); defer free(newtag); const range = fmt::asprintf("{}..HEAD", lasttag); @@ -142,6 +138,26 @@ fn do_initial_release() (void | release_error) = { fmt::fatal("TODO: Tag initial release"); }; +fn nextversion( + current: modversion, + next: (increment | modversion), +) modversion = { + const next = match (next) { + case incr: increment => + yield incr; + case ver: modversion => + return ver; + }; + switch (next) { + case increment::MAJOR => + return (current.0 + 1, 0, 0); + case increment::MINOR => + return (current.0, current.1 + 1, 0); + case increment::PATCH => + return (current.0, current.1, current.2 + 1); + }; +}; + fn checkbranch() (void | release_error) = { const default_branch = get_defaultbranch()?; defer free(default_branch); diff --git a/cmd/hare/subcmds.ha b/cmd/hare/subcmds.ha @@ -228,7 +228,7 @@ fn release(args: []str) void = { os::exit(1); }; - const increment = switch (cmd.args[0]) { + const next = switch (cmd.args[0]) { case "major" => yield increment::MAJOR; case "minor" => @@ -236,12 +236,16 @@ fn release(args: []str) void = { case "patch" => yield increment::PATCH; case => - // TODO: Manually parse version x.y.z - getopt::printusage(os::stderr, "release", help); - os::exit(1); + yield match (parseversion(cmd.args[0])) { + case badversion => + getopt::printusage(os::stderr, "release", help); + os::exit(1); + case ver: modversion => + yield ver; + }; }; - match (do_release(increment, dryrun)) { + match (do_release(next, dryrun)) { case void => void; case err: exec::error => fmt::fatal(exec::strerror(err));