Skip to content

Commit

Permalink
Support: Add wrapper functions to documentation (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskilding authored May 31, 2019
1 parent 060cbba commit e41cfc6
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ git tag | semver grep -o | semver sort -r | head -n 1
Validate a candidate version string:

```bash
[[ $(semver grep -q <<< "1.2.3-alpha+1") ]] && echo "Valid"
[[ $(semver grep -q <<< '1.2.3-alpha+1') ]] && echo 'Valid'
```

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

```bash
git tag | semver grep -o | xargs semver printf '%major,%minor,%patch,%prerelease,%build' {}
Expand All @@ -79,16 +79,41 @@ while curl -fs "https://example.com/artifact/$version.tar.gz" > "$version.tar.gz
done
```

Increment a version:
Increment the current Git tag:

```bash
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
current=$(git tag | semver grep -o | semver sort -r | head -n 1)
next=$(semver printf '%major %minor %patch' "$current" | awk '{ print ++$1 "." 0 "." 0 }')
```

Find filenames containing Semantic Versions inside a directory:

```bash
semver find . -type f
```
```

## Extras

The following wrapper functions can make common versioning operations easier.

```bash
#!/bin/sh

++major() {
semver printf '%major %minor %patch' "$1" | awk '{ print ++$1 "." 0 "." 0 }'
}

++minor() {
semver printf '%major %minor %patch' "$1" | awk '{ print $1 "." ++$2 "." 0 }'
}

++patch() {
semver printf '%major %minor %patch' "$1" | awk '{ print $1 "." $2 "." ++$3 }'
}
```

The above example of incrementing a Git tag then becomes:

```bash
++major $(git tag | semver grep -o | semver sort -r | head -n 1)
```

0 comments on commit e41cfc6

Please sign in to comment.