From ae4b9ba8973b1f8facb76cf2de51c3d276e2c04c Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Wed, 5 Apr 2017 20:46:25 +0100 Subject: [PATCH 1/2] cli: Fix "build" when the basename contains a "." Something like "moby-4.10.yml" did not work when invoked like "moby build moby-4.10". While at it, also allow .yaml as an extension. Signed-off-by: Rolf Neugebauer --- src/cmd/moby/build.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/moby/build.go b/src/cmd/moby/build.go index c029f5716..1c6efad6d 100644 --- a/src/cmd/moby/build.go +++ b/src/cmd/moby/build.go @@ -35,7 +35,7 @@ func build(args []string) { os.Exit(1) } conf := remArgs[0] - if filepath.Ext(conf) == "" { + if !(filepath.Ext(conf) == ".yml" || filepath.Ext(conf) == ".yaml") { conf = conf + ".yml" } From 048218f7c877450451f72352290c6ef2c0d976bd Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Wed, 5 Apr 2017 23:53:35 +0100 Subject: [PATCH 2/2] cli: Add a 'version' version Pass version and git commit hash from the Makefile into main.go. Add a 'version' subcommand to print the information. While at it also tweak the help output to only print the command name and not the entire path. Signed-off-by: Rolf Neugebauer --- src/cmd/moby/main.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/cmd/moby/main.go b/src/cmd/moby/main.go index 8496624bc..6ccf996a4 100644 --- a/src/cmd/moby/main.go +++ b/src/cmd/moby/main.go @@ -4,12 +4,19 @@ import ( "flag" "fmt" "os" + "path/filepath" log "github.com/Sirupsen/logrus" ) var ( defaultLogFormatter = &log.TextFormatter{} + + // Version is the human-readable version + Version = "unknown" + + // GitCommit hash, set at compile time + GitCommit = "unknown" ) // infoFormatter overrides the default format for Info() log events to @@ -24,15 +31,22 @@ func (f *infoFormatter) Format(entry *log.Entry) ([]byte, error) { return defaultLogFormatter.Format(entry) } +func version() { + fmt.Printf("%s version %s\n", filepath.Base(os.Args[0]), Version) + fmt.Printf("commit: %s\n", GitCommit) + os.Exit(0) +} + func main() { flag.Usage = func() { - fmt.Printf("USAGE: %s [options] COMMAND\n\n", os.Args[0]) + fmt.Printf("USAGE: %s [options] COMMAND\n\n", filepath.Base(os.Args[0])) fmt.Printf("Commands:\n") fmt.Printf(" build Build a Moby image from a YAML file\n") fmt.Printf(" run Run a Moby image on a local hypervisor\n") + fmt.Printf(" version Print version information\n") fmt.Printf(" help Print this message\n") fmt.Printf("\n") - fmt.Printf("Run '%s COMMAND --help' for more information on the command\n", os.Args[0]) + fmt.Printf("Run '%s COMMAND --help' for more information on the command\n", filepath.Base(os.Args[0])) fmt.Printf("\n") fmt.Printf("Options:\n") flag.PrintDefaults() @@ -69,6 +83,8 @@ func main() { build(args[1:]) case "run": run(args[1:]) + case "version": + version() case "help": flag.Usage() default: