Skip to content

Commit

Permalink
Include build metadata in -v output
Browse files Browse the repository at this point in the history
  • Loading branch information
foxcpp committed Mar 13, 2020
1 parent ff6eee1 commit 47f3d29
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
3 changes: 3 additions & 0 deletions docs/man/maddy.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ necessary to run secure email server implemented in one executable.
*-debug*
Enable debug log. You want to use it when reporting bugs.

*-v*
Print version & build metadata.

# Modules

maddy is built of many small components called "modules". Each module does one
Expand Down
23 changes: 15 additions & 8 deletions maddy.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (
)

var (
Version = "unknown (built from source tree)"
Version = "go-build"

// ConfigDirectory specifies platform-specific value
// that should be used as a location of default configuration
Expand Down Expand Up @@ -91,13 +91,20 @@ var (
)

func BuildInfo() string {
if info, ok := debug.ReadBuildInfo(); ok {
if info.Main.Version == "(devel)" {
return Version
}
return info.Main.Version + " " + info.Main.Sum
version := Version
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "(devel)" {
version = info.Main.Version
}
return Version + " (GOPATH build)"

return fmt.Sprintf(`%s %s/%s %s
default config: %s
default state_dir: %s
default runtime_dir: %s`,
version, runtime.GOOS, runtime.GOARCH, runtime.Version(),
filepath.Join(ConfigDirectory, "maddy.conf"),
DefaultStateDirectory,
DefaultRuntimeDirectory)
}

// Run is the entry point for all maddy code. It takes care of command line arguments parsing,
Expand All @@ -110,7 +117,7 @@ func Run() int {
var (
configPath = flag.String("config", filepath.Join(ConfigDirectory, "maddy.conf"), "path to configuration file")
logTargets = flag.String("log", "stderr", "default logging target(s)")
printVersion = flag.Bool("v", false, "print version and exit")
printVersion = flag.Bool("v", false, "print versio, build metadata and exit")
)

if enableDebugFlags {
Expand Down

0 comments on commit 47f3d29

Please sign in to comment.