Skip to content

Commit 8b8f449

Browse files
committed
cmd: add more info to --version
Signed-off-by: Aleksa Sarai <[email protected]>
1 parent bf94833 commit 8b8f449

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
4141
Note that this subcommand is not intended for wider use outside of our tests
4242
(and it is hidden from the help pages for a reason). Most users are probably
4343
better off just using `gomtree`.
44+
* `umoci --version` now provides more information about the specification
45+
versions supported by the `umoci` binary as well as the Go version used.
4446

4547
### Changed ###
4648
* The output format of `umoci stat` has had some minor changes made to how

cmd/umoci/main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ import (
2323
"errors"
2424
"fmt"
2525
"os"
26+
"runtime"
2627
"runtime/pprof"
2728

2829
"github.com/apex/log"
2930
logcli "github.com/apex/log/handlers/cli"
31+
imeta "github.com/opencontainers/image-spec/specs-go"
32+
rspec "github.com/opencontainers/runtime-spec/specs-go"
3033
"github.com/urfave/cli"
3134

3235
"github.com/opencontainers/umoci"
@@ -40,6 +43,15 @@ const (
4043
categoryImage = "image"
4144
)
4245

46+
func printVersion(c *cli.Context) {
47+
w := c.App.Writer
48+
49+
fmt.Fprintln(w, "umoci version", c.App.Version) //nolint:errcheck // errors not relevant
50+
fmt.Fprintln(w, "image spec:", imeta.Version) //nolint:errcheck // errors not relevant
51+
fmt.Fprintln(w, "runtime spec:", rspec.Version) //nolint:errcheck // errors not relevant
52+
fmt.Fprintln(w, "go:", runtime.Version()) //nolint:errcheck // errors not relevant
53+
}
54+
4355
// Main is the underlying main() implementation. You can call this directly as
4456
// though it were the command-line arguments of the umoci binary (this is
4557
// needed for umoci's integration test hacks you can find in main_test.go).
@@ -53,7 +65,9 @@ func Main(args []string) error {
5365
5466
},
5567
}
68+
5669
app.Version = umoci.FullVersion()
70+
cli.VersionPrinter = printVersion
5771

5872
app.Flags = []cli.Flag{
5973
cli.BoolFlag{

test/help.bats

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@ load helpers
2222

2323
umoci --version
2424
[ "$status" -eq 0 ]
25-
[[ "$output" =~ "umoci version $VERSION"+ ]]
25+
[[ "$output" == "umoci version $VERSION"* ]]
26+
[[ "$output" == *"image spec: 1."* ]]
27+
[[ "$output" == *"runtime spec: 1."* ]]
28+
[[ "$output" == *"go: go1."* ]]
2629

2730
umoci -v
2831
[ "$status" -eq 0 ]
29-
[[ "$output" =~ "umoci version $VERSION"+ ]]
32+
[[ "$output" == "umoci version $VERSION"* ]]
33+
[[ "$output" == *"image spec: 1."* ]]
34+
[[ "$output" == *"runtime spec: 1."* ]]
35+
[[ "$output" == *"go: go1."* ]]
3036
}
3137

3238
@test "umoci --help" {

0 commit comments

Comments
 (0)