Skip to content

Commit 10ee765

Browse files
authored
Support: Improve documentation (#47)
1 parent f8243a4 commit 10ee765

File tree

2 files changed

+77
-52
lines changed

2 files changed

+77
-52
lines changed

README.md

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55

66
Semantic Versioning utility.
77

8-
## Overview
8+
## Description
99

10-
The `semver` command line utility extracts, parses, sorts, and validates [Semantic Version](https://semver.org/) strings.
10+
The `semver` utility is a text filter for [Semantic Version](https://semver.org/) strings. It searches text from the standard input, selects any Semantic Versions that are present, and writes them to the standard output. It can optionally sort or tabulate the selected versions.
1111

12-
The Semantic Versioning format is:
12+
A *version* string will be selected within the text stream if the following criteria are met:
1313

14-
major.minor.patch[-prerelease][+build]
15-
16-
Examples: `1.2.3`, `1.2.3-alpha`, `1.2.3+2008`, `1.2.3-alpha+2008`.
14+
- *version* is a valid Semantic Version.
15+
- *version* is a whole line. (This can be modified with the `-w` option.)
1716

1817
## Install
1918

@@ -45,7 +44,7 @@ Options:
4544
- `-t --tabulate`
4645
Tabulate the matched versions (separator: '\t').
4746
- `-w --word-match`
48-
Select words that match the semver pattern.
47+
Select words that match the semver pattern. (Equivalent to the *grep(1)* `--word-regexp` option.)
4948

5049
Most options can be combined. For example, `semver -stw` will word-match occurrences of semvers, sort them, and print them in tabulated form.
5150

@@ -57,6 +56,25 @@ man semver
5756

5857
## Examples
5958

59+
**Select** lines that are version strings:
60+
61+
```bash
62+
semver < example.txt
63+
```
64+
65+
**Calculate** the next Git tag:
66+
67+
```bash
68+
# ++major
69+
git tag | semver -st | tail -n 1 | awk -F '\t' '{ print ++$1 "." 0 "." 0 }'
70+
71+
# ++minor
72+
git tag | semver -st | tail -n 1 | awk -F '\t' '{ print $1 "." ++$2 "." 0 }'
73+
74+
# ++patch
75+
git tag | semver -st | tail -n 1 | awk -F '\t' '{ print $1 "." $2 "." ++$3 }'
76+
```
77+
6078
**Cut** out the major, minor, and patch components of a version:
6179

6280
```bash
@@ -72,33 +90,48 @@ while curl -fs "https://example.com/artifact/$v.tar.gz" > "$v.tar.gz"; do
7290
done
7391
```
7492

93+
**Find** the current Git tag:
94+
95+
```bash
96+
git tag | semver -s | tail -n 1
97+
```
98+
7599
**Format** versions as CSV:
76100

77101
```bash
78-
semver -tw < versions.txt | tr '\t' ','
102+
semver -tw < example.txt | tr '\t' ','
79103
```
80104

81-
**Get** the latest Git tag:
105+
**Validate** a candidate version string:
82106

83107
```bash
84-
git tag | semver -s | tail -n 1
108+
semver -q <<< '1.2.3' && echo 'ok'
85109
```
86110

87-
**Increment** the current Git tag:
111+
## Functions
112+
113+
These Bash helper functions can make complex versioning operations easier.
88114

89115
```bash
90-
# ++major
91-
git tag | semver -st | tail -n 1 | awk -F '\t' '{ print ++$1 "." 0 "." 0 }'
116+
#!/usr/bin/env bash
92117

93-
# ++minor
94-
git tag | semver -st | tail -n 1 | awk -F '\t' '{ print $1 "." ++$2 "." 0 }'
118+
function ++major {
119+
semver -t <<< "$1" | awk -F '\t' '{ print ++$1 "." 0 "." 0 }'
120+
}
95121

96-
# ++patch
97-
git tag | semver -st | tail -n 1 | awk -F '\t' '{ print $1 "." $2 "." ++$3 }'
122+
function ++minor {
123+
semver -t <<< "$1" | awk -F '\t' '{ print $1 "." ++$2 "." 0 }'
124+
}
125+
126+
function ++patch {
127+
semver -t <<< "$1" | awk -F '\t' '{ print $1 "." $2 "." ++$3 }'
128+
}
98129
```
99130

100-
**Validate** a candidate version string:
131+
Examples:
101132

102133
```bash
103-
semver -q <<< '1.2.3' && echo 'ok'
134+
++major '1.2.3' #=> 2.0.0
135+
++minor '1.2.3' #=> 1.3.0
136+
++patch '1.2.3' #=> 1.2.4
104137
```

semver.1

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
.Sh DESCRIPTION
1111
The
1212
.Nm
13-
utility can search text from the standard input, select any Semantic Version strings that are
14-
present, and write them to the standard output. It can optionally sort or tabulate the selected
13+
utility is a text filter for Semantic Version strings. It searches text from the standard input, selects any Semantic
14+
Versions that are present, and writes them to the standard output. It can optionally sort or tabulate the selected
1515
versions.
1616
.Pp
1717
A
1818
.Sq version
19-
string will be matched within the text stream if the following criteria are met:
19+
string will be selected within the text stream if the following criteria are met:
2020
.Bl -bullet -compact
2121
.It
2222
.Sq version
@@ -27,20 +27,6 @@ is a whole line. (This can be modified with the
2727
.Fl w
2828
option.)
2929
.El
30-
.Pp
31-
Example:
32-
.Pp
33-
.Bd -literal -offset indent
34-
$ semver <<EOF
35-
1.1.1
36-
bar
37-
2.2.2-alpha+1
38-
foo-3.3.3.txt
39-
EOF
40-
41-
1.1.1
42-
2.2.2-alpha+1
43-
.Ed
4430
.Sh OPTIONS
4531
.Pp
4632
The
@@ -114,6 +100,25 @@ EOF
114100
.El
115101
.Sh EXAMPLES
116102
.Pp
103+
\fBSelect\fR lines that are version strings:
104+
.Pp
105+
.Bd -literal -offset indent -compact
106+
semver < example.txt
107+
.Ed
108+
.Pp
109+
\fBCalculate\fR the next Git tag:
110+
.Pp
111+
.Bd -literal -offset indent -compact
112+
# major++
113+
git tag | semver -st | tail -n 1 | awk -F '\\t' '{ print ++$1 "." 0 "." 0 }'
114+
115+
# minor++
116+
git tag | semver -st | tail -n 1 | awk -F '\\t' '{ print $1 "." ++$2 "." 0 }'
117+
118+
# patch++
119+
git tag | semver -st | tail -n 1 | awk -F '\\t' '{ print $1 "." $2 "." ++$3 }'
120+
.Ed
121+
.Pp
117122
\fBCut\fR out the major, minor, and patch components of versions:
118123
.Pp
119124
.Bd -literal -offset indent -compact
@@ -129,29 +134,16 @@ while curl -fs "https://example.com/artifact/$v.tar.gz" > "$v.tar.gz"; do
129134
done
130135
.Ed
131136
.Pp
132-
\fBFormat\fR version strings as CSV:
133-
.Pp
134-
.Bd -literal -offset indent -compact
135-
semver -tw < versions.txt | tr '\\t' ','
136-
.Ed
137-
.Pp
138-
\fBGet\fR the current Git tag:
137+
\fBFind\fR the current Git tag:
139138
.Pp
140139
.Bd -literal -offset indent -compact
141140
git tag | semver -s | tail -n 1
142141
.Ed
143142
.Pp
144-
\fBIncrement\fR the Git tag:
143+
\fBFormat\fR version strings as CSV:
145144
.Pp
146145
.Bd -literal -offset indent -compact
147-
# major++
148-
git tag | semver -st | tail -n 1 | awk -F '\\t' '{ print ++$1 "." 0 "." 0 }'
149-
150-
# minor++
151-
git tag | semver -st | tail -n 1 | awk -F '\\t' '{ print $1 "." ++$2 "." 0 }'
152-
153-
# patch++
154-
git tag | semver -st | tail -n 1 | awk -F '\\t' '{ print $1 "." $2 "." ++$3 }'
146+
semver -tw < example.txt | tr '\\t' ','
155147
.Ed
156148
.Pp
157149
\fBValidate\fR a candidate version string:

0 commit comments

Comments
 (0)