Skip to content

Commit

Permalink
Merge pull request #2790 from ipfs/feature/version-all
Browse files Browse the repository at this point in the history
Add version --all option
  • Loading branch information
whyrusleeping committed Jun 2, 2016
2 parents 082393d + c8c329d commit 994109c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
17 changes: 17 additions & 0 deletions core/commands/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands
import (
"fmt"
"io"
"runtime"
"strings"

cmds "github.com/ipfs/go-ipfs/commands"
Expand All @@ -14,6 +15,8 @@ type VersionOutput struct {
Version string
Commit string
Repo string
System string
Golang string
}

var VersionCmd = &cmds.Command{
Expand All @@ -26,12 +29,15 @@ var VersionCmd = &cmds.Command{
cmds.BoolOption("number", "n", "Only show the version number.").Default(false),
cmds.BoolOption("commit", "Show the commit hash.").Default(false),
cmds.BoolOption("repo", "Show repo version.").Default(false),
cmds.BoolOption("all", "Show all version information").Default(false),
},
Run: func(req cmds.Request, res cmds.Response) {
res.SetOutput(&VersionOutput{
Version: config.CurrentVersionNumber,
Commit: config.CurrentCommit,
Repo: fsrepo.RepoVersion,
System: runtime.GOARCH + "/" + runtime.GOOS, //TODO: Precise version here
Golang: runtime.Version(),
})
},
Marshalers: cmds.MarshalerMap{
Expand Down Expand Up @@ -64,6 +70,17 @@ var VersionCmd = &cmds.Command{
return strings.NewReader(fmt.Sprintln(v.Version + commitTxt)), nil
}

all, _, err := res.Request().Option("all").Bool()
if err != nil {
return nil, err
}
if all {
out := fmt.Sprintf("go-ipfs version: %s-%s\n"+
"Repo version: %s\nSystem version: %s\nGolang version: %s\n",
v.Version, v.Commit, v.Repo, v.System, v.Golang)
return strings.NewReader(out), nil
}

return strings.NewReader(fmt.Sprintf("ipfs version %s%s\n", v.Version, commitTxt)), nil
},
},
Expand Down
8 changes: 8 additions & 0 deletions test/sharness/t0010-basic-commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ test_expect_success "ipfs version output looks good" '
test_fsh cat version.txt
'

test_expect_success "ipfs version --all has all required fields" '
ipfs version --all > version_all.txt &&
grep "go-ipfs version" version_all.txt &&
grep "Repo version" version_all.txt &&
grep "System version" version_all.txt &&
grep "Golang version" version_all.txt
'

test_expect_success "ipfs help succeeds" '
ipfs help >help.txt
'
Expand Down
2 changes: 1 addition & 1 deletion test/sharness/t0500-issues-and-regressions-offline.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

test_description="Tests for various fxed issues and regressions."
test_description="Tests for various fixed issues and regressions."

. lib/test-lib.sh

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

test_description="Tests for various fxed issues and regressions."
test_description="Tests for various fixed issues and regressions."

. lib/test-lib.sh

Expand Down

0 comments on commit 994109c

Please sign in to comment.