From c43abd765cf51c06bbcaa5479dc49aab1396989f Mon Sep 17 00:00:00 2001 From: Anthony Fok Date: Wed, 26 Feb 2020 17:17:12 -0700 Subject: [PATCH] Print dh-make-golang version at the start of make Set to v0.3.3 release --- main.go | 12 ++++++++---- make.go | 8 ++++++++ version_current.go | 31 +++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 version_current.go diff --git a/main.go b/main.go index 3c1e8a6..adb5a27 100644 --- a/main.go +++ b/main.go @@ -8,16 +8,20 @@ import ( "github.com/gregjones/httpcache" ) +const program = "dh-make-golang" + var ( gitHub *github.Client ) func usage() { - fmt.Fprintf(os.Stderr, "%s is a tool that converts Go packages into Debian package source.\n", os.Args[0]) + fmt.Fprintf(os.Stderr, "%s\n", buildVersionString()) + fmt.Fprintf(os.Stderr, "\n") + fmt.Fprintf(os.Stderr, "%s is a tool that converts Go packages into Debian package source.\n", program) fmt.Fprintf(os.Stderr, "\n") - fmt.Fprintf(os.Stderr, "Usage:\n\t%s [globalflags] [flags] \n", os.Args[0]) + fmt.Fprintf(os.Stderr, "Usage:\n\t%s [globalflags] [flags] \n", program) fmt.Fprintf(os.Stderr, "\n") - fmt.Fprintf(os.Stderr, "%s commands:\n", os.Args[0]) + fmt.Fprintf(os.Stderr, "%s commands:\n", program) fmt.Fprintf(os.Stderr, "\tmake\t\t\tcreate a Debian package\n") fmt.Fprintf(os.Stderr, "\tsearch\t\t\tsearch Debian for already-existing packages\n") fmt.Fprintf(os.Stderr, "\testimate\t\testimate the amount of work for a package\n") @@ -25,7 +29,7 @@ func usage() { fmt.Fprintf(os.Stderr, "\n") fmt.Fprintf(os.Stderr, "For backwards compatibility, when no command is specified,\nthe make command is executed.\n") fmt.Fprintf(os.Stderr, "\n") - fmt.Fprintf(os.Stderr, "To learn more about a command, run \"%s -help\",\ne.g. \"%s make -help\"\n", os.Args[0], os.Args[0]) + fmt.Fprintf(os.Stderr, "To learn more about a command, run \"%s -help\",\ne.g. \"%s make -help\"\n", program, program) fmt.Fprintf(os.Stderr, "\n") } diff --git a/make.go b/make.go index 3e89cbb..56fb909 100644 --- a/make.go +++ b/make.go @@ -784,6 +784,14 @@ func execMake(args []string, usage func()) { "Valid values are \"a\", \"at\" and \"ast\", see wrap-and-sort(1) man page\n"+ "for more information.") + // ==================================================================== + // + // Start actual make routine + // + // ==================================================================== + + log.Printf("Starting %q", buildVersionString()) + err := fs.Parse(args) if err != nil { log.Fatal(err) diff --git a/version_current.go b/version_current.go new file mode 100644 index 0000000..0cd0cd7 --- /dev/null +++ b/version_current.go @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "runtime" +) + +// Version represents the dh-make-golang build version. +type Version struct { + major int + minor int + patch int + preRelease string +} + +var currentVersion = Version{ + major: 0, + minor: 3, + patch: 3, + preRelease: "", +} + +func (v Version) String() string { + return fmt.Sprintf("%d.%d.%d%s", v.major, v.minor, v.patch, v.preRelease) +} + +func buildVersionString() string { + version := "v" + currentVersion.String() + osArch := runtime.GOOS + "/" + runtime.GOARCH + return fmt.Sprintf("%s %s %s", program, version, osArch) +}