commands/run.go: make --version synonymous with version()

This commit is contained in:
Taylor Blau 2018-05-21 18:19:33 -07:00
parent 71f6f2ccdb
commit 1c665a3534
2 changed files with 30 additions and 1 deletions

@ -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) {

23
test/test-version.sh Executable file

@ -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