From 1c665a3534b482f9c90d9ed66ad9d04552bf3aae Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Mon, 21 May 2018 18:19:33 -0700 Subject: [PATCH] commands/run.go: make --version synonymous with version() --- commands/run.go | 8 +++++++- test/test-version.sh | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100755 test/test-version.sh diff --git a/commands/run.go b/commands/run.go index de7409a0..823e76b2 100644 --- a/commands/run.go +++ b/commands/run.go @@ -16,6 +16,8 @@ import ( var ( commandFuncs []func() *cobra.Command commandMu sync.Mutex + + rootVersion bool ) // NewCommand creates a new 'git-lfs' sub command, given a command name and @@ -62,6 +64,8 @@ func Run() int { root.SetHelpFunc(helpCommand) root.SetUsageFunc(usageCommand) + root.Flags().BoolVarP(&rootVersion, "version", "v", false, "") + cfg = config.New() for _, f := range commandFuncs { @@ -81,7 +85,9 @@ func Run() int { func gitlfsCommand(cmd *cobra.Command, args []string) { versionCommand(cmd, args) - cmd.Usage() + if !rootVersion { + cmd.Usage() + } } func helpCommand(cmd *cobra.Command, args []string) { diff --git a/test/test-version.sh b/test/test-version.sh new file mode 100755 index 00000000..31dfdb7f --- /dev/null +++ b/test/test-version.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +. "test/testlib.sh" + +begin_test "git lfs --version is a synonym of git lfs version" +( + set -e + + reponame="git-lfs-version-synonymous" + mkdir "$reponame" + cd "$reponame" + + git lfs version 2>&1 >version.log + git lfs --version 2>&1 >flag.log + + if [ "$(cat version.log)" != "$(cat flag.log)" ]; then + echo >&2 "fatal: expected 'git lfs version' and 'git lfs --version' to" + echo >&2 "produce identical output ..." + + diff -u {version,flag}.log + fi +) +end_test