aboutsummaryrefslogtreecommitdiff
path: root/cmd/version.go
diff options
context:
space:
mode:
authorJoe Richey joerichey@google.com <joerichey@google.com>2017-10-12 17:59:45 -0700
committerJoseph Richey <joerichey94@gmail.com>2017-10-19 02:22:25 -0700
commitb4299090c3e503ba0c49a6086b1a46c218ca45f4 (patch)
tree889adbf3da9616a5c6eaa783291e5f94c01955a2 /cmd/version.go
parent921f1c977c4e0704f61e3a7c092d3a4317ab278c (diff)
Command, Context, command line splitting setup
Diffstat (limited to 'cmd/version.go')
-rw-r--r--cmd/version.go57
1 files changed, 37 insertions, 20 deletions
diff --git a/cmd/version.go b/cmd/version.go
index 787e2cd..99097b5 100644
--- a/cmd/version.go
+++ b/cmd/version.go
@@ -19,44 +19,61 @@
package cmd
+import (
+ "fmt"
+
+ "github.com/blang/semver"
+)
+
// Templates for use with the version command, which both parse the Info var.
var (
- VersionShortTemplate = "{{.Command}} version {{.VersionTag}}\n"
- VersionLongTemplate = VersionShortTemplate + `{{if .Compiled}}
+ VersionTemplate = "{{.FullName}} {{.Info.Version}}\n"
+ VersionLongTemplate = `{{if .Info.BuildTime}}
Compiled:
- {{.Compiled}}
-{{end}}{{if len .Authors}}
-Author{{with $length := len .Authors}}{{if ne 1 $length}}s{{end}}{{end}}:{{range .Authors}}
- {{.}}{{end}}
-{{end}}{{if .Copyright}}
+ {{.Info.BuildTime}}
+{{end}}
+
+{{with $length := len .Info.Authors}}
+{{if $length}}
+Author{{if ne 1 $length}}s{{end}}:
+{{range .Info.Authors}}
+ {{.Name}}{{if .Email}} <{{.Email}}>{{end}}
+{{end}}
+{{end}}
+{{end}}
+
+{{if .Info.Copyright}}
Copyright:
- {{.Copyright}}
+{{.Info.Copyright}}
{{end}}`
)
-// Version is a command which will display either the VersionTag (by default) or
-// the full version information (version, copyright, authors).
-var Version = &Command{
+// VersionCommand is a command which will display either the VersionTag (by
+// default) or the full version information: version, copyright, authors, etc...
+var VersionCommand = &Command{
Name: "version",
- UsageLines: []string{""},
- Flags: []Flag{longFlag},
+ Title: "display this program's version information",
+ UsageLines: []string{fmt.Sprintf("[%v]", longFlag)},
+ Flags: []Flag{longFlag, HelpFlag},
Action: versionAction,
}
-// Using longFlag with the version command displays the longer version info.
+// VersionUsage is a UsageLine to add to a Command with a version Subcommand.
+var VersionUsage = VersionCommand.Name + " " + VersionCommand.UsageLines[0]
+
+// longFlag tells the version command to display the longer version info.
var longFlag = &BoolFlag{
Name: "long",
- Usage: "Print the detailed version and copyright information.",
+ Usage: "Print the detailed version, build, and copyright information.",
}
-func versionAction(_ []string) error {
- if Info.VersionTag == "" {
+func versionAction(ctx *Context) error {
+ if ctx.Info.Version.Equals(semver.Version{}) {
return ErrUnknownVersion
}
+ ctx.executeTemplate(Output, VersionTemplate)
if longFlag.Value {
-
- } else {
-
+ ctx.executeTemplate(Output, VersionLongTemplate)
}
return nil
}