Skip to content

Commit

Permalink
commands/run.go: make --version synonymous with version()
Browse files Browse the repository at this point in the history
  • Loading branch information
ttaylorr committed May 22, 2018
1 parent 56756a5 commit 7933647
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
8 changes: 7 additions & 1 deletion commands/run.go
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down
23 changes: 23 additions & 0 deletions 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

0 comments on commit 7933647

Please sign in to comment.