File tree 5 files changed +75
-1
lines changed
5 files changed +75
-1
lines changed Original file line number Diff line number Diff line change
1
+ package app
2
+
3
+ import (
4
+ "fmt"
5
+ "os"
6
+ "runtime"
7
+ "text/template"
8
+
9
+ "github.com/Sirupsen/logrus"
10
+ "github.com/codegangsta/cli"
11
+ "github.com/docker/libcompose/version"
12
+ )
13
+
14
+ var versionTemplate = `Version: {{.Version}} ({{.GitCommit}})
15
+ Go version: {{.GoVersion}}
16
+ Built: {{.BuildTime}}
17
+ OS/Arch: {{.Os}}/{{.Arch}}`
18
+
19
+ // Version prints the libcompose version number and additionnal informations.
20
+ func Version (c * cli.Context ) {
21
+ if c .Bool ("short" ) {
22
+ fmt .Println (version .VERSION )
23
+ return
24
+ }
25
+
26
+ tmpl , err := template .New ("" ).Parse (versionTemplate )
27
+ if err != nil {
28
+ logrus .Fatal (err )
29
+ }
30
+
31
+ v := struct {
32
+ Version string
33
+ GitCommit string
34
+ GoVersion string
35
+ BuildTime string
36
+ Os string
37
+ Arch string
38
+ }{
39
+ Version : version .VERSION ,
40
+ GitCommit : version .GITCOMMIT ,
41
+ GoVersion : runtime .Version (),
42
+ BuildTime : version .BUILDTIME ,
43
+ Os : runtime .GOOS ,
44
+ Arch : runtime .GOARCH ,
45
+ }
46
+
47
+ if err := tmpl .Execute (os .Stdout , v ); err != nil {
48
+ logrus .Fatal (err )
49
+ }
50
+ fmt .Printf ("\n " )
51
+ return
52
+ }
Original file line number Diff line number Diff line change @@ -276,6 +276,21 @@ func UnpauseCommand(factory app.ProjectFactory) cli.Command {
276
276
}
277
277
}
278
278
279
+ // VersionCommand defines the libcompose version subcommand.
280
+ func VersionCommand (factory app.ProjectFactory ) cli.Command {
281
+ return cli.Command {
282
+ Name : "version" ,
283
+ Usage : "Show version informations" ,
284
+ Action : app .Version ,
285
+ Flags : []cli.Flag {
286
+ cli.BoolFlag {
287
+ Name : "short" ,
288
+ Usage : "Shows only Compose's version number." ,
289
+ },
290
+ },
291
+ }
292
+ }
293
+
279
294
// CommonFlags defines the flags that are in common for all subcommands.
280
295
func CommonFlags () []cli.Flag {
281
296
return []cli.Flag {
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ func main() {
39
39
command .StopCommand (factory ),
40
40
command .UnpauseCommand (factory ),
41
41
command .UpCommand (factory ),
42
+ command .VersionCommand (factory ),
42
43
}
43
44
44
45
app .Run (os .Args )
Original file line number Diff line number Diff line change @@ -6,8 +6,11 @@ rm -f libcompose-cli
6
6
7
7
go generate
8
8
9
+ BUILDTIME=$( date --rfc-3339 ns | sed -e ' s/ /T/' ) & > /dev/null
10
+ GITCOMMIT=$( git rev-parse --short HEAD)
11
+
9
12
# Build binaries
10
13
go build \
11
- -ldflags=" -w -X github.com/docker/libcompose/version.GITCOMMIT=` git rev-parse --short HEAD ` " \
14
+ -ldflags=" -w -X github.com/docker/libcompose/version.GITCOMMIT=${GITCOMMIT} -X github.com/docker/libcompose/version.BUILDTIME= ${BUILDTIME} " \
12
15
-o bundles/libcompose-cli \
13
16
./cli/main
Original file line number Diff line number Diff line change 6
6
7
7
// GITCOMMIT will be overwritten automatically by the build system
8
8
GITCOMMIT = "HEAD"
9
+
10
+ // BUILDTIME will be overwritten automatically by the build system
11
+ BUILDTIME = ""
9
12
)
You can’t perform that action at this time.
0 commit comments