Skip to content

Commit

Permalink
Support: Remove increment and decrement subcommands (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskilding authored May 27, 2019
1 parent b649979 commit 44ed274
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 539 deletions.
34 changes: 21 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ Coming soon.

## Usage

semver decrement [-major | -minor | -patch] <version>
semver grep [-coq] -
semver increment [-major | -minor | -patch] <version>
semver printf <format> <version>
semver sort [-r] -
semver [-h]
```bash
semver grep [-coq] -
semver printf <format> <version>
semver sort [-r] -
semver [-h]
```

Man page:
Manual:

```bash
$ man semver
man semver
```

## Examples
Expand All @@ -63,17 +63,25 @@ Validate a candidate version string:
[[ $(semver grep -q <<< "1.2.3-alpha+1") ]] && echo "Valid"
```

Format a list of version strings as CSV:

```bash
git tag | semver grep -o | xargs semver printf '%major,%minor,%patch,%prerelease,%build' {}
```

Download all artifacts in a version range:

```bash
version="0.0.1"
version='0.0.1'
while curl -fs "https://example.com/artifact/$version.tar.gz" > "$version.tar.gz"; do
version=$(semver increment -patch ${version})
version=$(semver printf '%major %minor %patch' "$version" | awk '{ print $1 "." $2 "." ++$3 }')
done
```

Format a list of version strings as CSV:
Increment a version:

```bash
git tag | semver grep -o | xargs semver printf "%major,%minor,%patch,%prerelease,%build" {}
```
semver printf '%major %minor %patch' '1.2.3-alpha+1' | awk '{ print ++$1 "." 0 "." 0 }' # => 2.0.0
semver printf '%major %minor %patch' '1.2.3-alpha+1' | awk '{ print $1 "." ++$2 "." 0 }' # => 1.3.0
semver printf '%major %minor %patch' '1.2.3-alpha+1' | awk '{ print $1 "." $2 "." ++$3 }' # => 1.2.4
```
128 changes: 0 additions & 128 deletions semver
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ sub usage() {
say STDERR "Semantic Versioning utility.";
say STDERR "";
say STDERR "Usage:";
say STDERR " $program decrement [-major | -minor | -patch] <version>";
say STDERR " $program grep [-coq] -";
say STDERR " $program increment [-major | -minor | -patch] <version>";
say STDERR " $program printf <format> <version>";
say STDERR " $program sort [-r] -";
say STDERR " $program [-h]";
Expand Down Expand Up @@ -148,54 +146,6 @@ sub semver::compare {
}
}

sub semver::decrement_major {
my ($version) = @_;

my @matches = semver_get($version);

my $major = $matches[0];

if ($major > 0) {
my $new_major = $major - 1;
say "$new_major.0.0";
} else {
exit 1;
}
}

sub semver::decrement_minor {
my ($version) = @_;

my @matches = semver_get($version);

my $major = $matches[0];
my $minor = $matches[1];

if ($minor > 0) {
my $new_minor = $minor - 1;
say "$major.$new_minor.0";
} else {
exit 1;
}
}

sub semver::decrement_patch {
my ($version) = @_;

my @matches = semver_get($version);

my $major = $matches[0];
my $minor = $matches[1];
my $patch = $matches[2];

if ($patch > 0) {
my $new_patch = $patch - 1;
say "$major.$minor.$new_patch";
} else {
exit 1;
}
}

sub semver::printf {
my ($format, $version) = @_;

Expand Down Expand Up @@ -291,42 +241,6 @@ sub semver::grep {
}
}

sub semver::increment_major {
my ($version) = @_;

my @matches = semver_get($version);

my $major = $matches[0];
my $new_major = $major + 1;

say "$new_major.0.0";
}

sub semver::increment_minor {
my ($version) = @_;

my @matches = semver_get($version);

my $major = $matches[0];
my $minor = $matches[1];
my $new_minor = $minor + 1;

say "$major.$new_minor.0";
}

sub semver::increment_patch {
my ($version) = @_;

my @matches = semver_get($version);

my $major = $matches[0];
my $minor = $matches[1];
my $patch = $matches[2];
my $new_patch = $patch + 1;

say "$major.$minor.$new_patch";
}

sub semver::sort(&@) {
my ($sort_fn) = @_;

Expand Down Expand Up @@ -364,27 +278,6 @@ sub main {
my $subcommand = shift @args // '';

for ($subcommand) {
when (/^decrement$/) {
my $operator = $args[0];
my $version = $args[1];

usage() if (scalar(@args) != 2);

for ($operator) {
when (/^-major$/) {
semver::decrement_major($version);
}
when (/^-minor$/) {
semver::decrement_minor($version);
}
when (/^-patch$/) {
semver::decrement_patch($version);
}
default {
usage();
}
}
}
when (/^grep$/) {
my $count, my $only_matching, my $quiet, my $help;

Expand All @@ -406,27 +299,6 @@ sub main {
semver::grep($only_matching);
}
}
when (/^increment$/) {
my $operator = $args[0];
my $version = $args[1];

usage() if (scalar(@args) != 2);

for ($operator) {
when (/^-major$/) {
semver::increment_major($version);
}
when (/^-minor$/) {
semver::increment_minor($version);
}
when (/^-patch$/) {
semver::increment_patch($version);
}
default {
usage();
}
}
}
when (/^printf$/) {
usage() if (scalar(@args) < 2);

Expand Down
Loading

0 comments on commit 44ed274

Please sign in to comment.