Skip to content

Commit 7933647

Browse files
committed
commands/run.go: make --version synonymous with version()
1 parent 56756a5 commit 7933647

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

commands/run.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
var (
1717
commandFuncs []func() *cobra.Command
1818
commandMu sync.Mutex
19+
20+
rootVersion bool
1921
)
2022

2123
// NewCommand creates a new 'git-lfs' sub command, given a command name and
@@ -62,6 +64,8 @@ func Run() int {
6264
root.SetHelpFunc(helpCommand)
6365
root.SetUsageFunc(usageCommand)
6466

67+
root.Flags().BoolVarP(&rootVersion, "version", "v", false, "")
68+
6569
cfg = config.New()
6670

6771
for _, f := range commandFuncs {
@@ -81,7 +85,9 @@ func Run() int {
8185

8286
func gitlfsCommand(cmd *cobra.Command, args []string) {
8387
versionCommand(cmd, args)
84-
cmd.Usage()
88+
if !rootVersion {
89+
cmd.Usage()
90+
}
8591
}
8692

8793
func helpCommand(cmd *cobra.Command, args []string) {

test/test-version.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
. "test/testlib.sh"
4+
5+
begin_test "git lfs --version is a synonym of git lfs version"
6+
(
7+
set -e
8+
9+
reponame="git-lfs-version-synonymous"
10+
mkdir "$reponame"
11+
cd "$reponame"
12+
13+
git lfs version 2>&1 >version.log
14+
git lfs --version 2>&1 >flag.log
15+
16+
if [ "$(cat version.log)" != "$(cat flag.log)" ]; then
17+
echo >&2 "fatal: expected 'git lfs version' and 'git lfs --version' to"
18+
echo >&2 "produce identical output ..."
19+
20+
diff -u {version,flag}.log
21+
fi
22+
)
23+
end_test

0 commit comments

Comments
 (0)