提交 994109c7 作者: Jeromy Johnson

Merge pull request #2790 from ipfs/feature/version-all

Add version --all option
...@@ -3,6 +3,7 @@ package commands ...@@ -3,6 +3,7 @@ package commands
import ( import (
"fmt" "fmt"
"io" "io"
"runtime"
"strings" "strings"
cmds "github.com/ipfs/go-ipfs/commands" cmds "github.com/ipfs/go-ipfs/commands"
...@@ -14,6 +15,8 @@ type VersionOutput struct { ...@@ -14,6 +15,8 @@ type VersionOutput struct {
Version string Version string
Commit string Commit string
Repo string Repo string
System string
Golang string
} }
var VersionCmd = &cmds.Command{ var VersionCmd = &cmds.Command{
...@@ -26,12 +29,15 @@ var VersionCmd = &cmds.Command{ ...@@ -26,12 +29,15 @@ var VersionCmd = &cmds.Command{
cmds.BoolOption("number", "n", "Only show the version number.").Default(false), cmds.BoolOption("number", "n", "Only show the version number.").Default(false),
cmds.BoolOption("commit", "Show the commit hash.").Default(false), cmds.BoolOption("commit", "Show the commit hash.").Default(false),
cmds.BoolOption("repo", "Show repo version.").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) { Run: func(req cmds.Request, res cmds.Response) {
res.SetOutput(&VersionOutput{ res.SetOutput(&VersionOutput{
Version: config.CurrentVersionNumber, Version: config.CurrentVersionNumber,
Commit: config.CurrentCommit, Commit: config.CurrentCommit,
Repo: fsrepo.RepoVersion, Repo: fsrepo.RepoVersion,
System: runtime.GOARCH + "/" + runtime.GOOS, //TODO: Precise version here
Golang: runtime.Version(),
}) })
}, },
Marshalers: cmds.MarshalerMap{ Marshalers: cmds.MarshalerMap{
...@@ -64,6 +70,17 @@ var VersionCmd = &cmds.Command{ ...@@ -64,6 +70,17 @@ var VersionCmd = &cmds.Command{
return strings.NewReader(fmt.Sprintln(v.Version + commitTxt)), nil 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 return strings.NewReader(fmt.Sprintf("ipfs version %s%s\n", v.Version, commitTxt)), nil
}, },
}, },
......
...@@ -21,6 +21,14 @@ test_expect_success "ipfs version output looks good" ' ...@@ -21,6 +21,14 @@ test_expect_success "ipfs version output looks good" '
test_fsh cat version.txt 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" ' test_expect_success "ipfs help succeeds" '
ipfs help >help.txt ipfs help >help.txt
' '
......
#!/bin/sh #!/bin/sh
test_description="Tests for various fxed issues and regressions." test_description="Tests for various fixed issues and regressions."
. lib/test-lib.sh . lib/test-lib.sh
......
#!/bin/sh #!/bin/sh
test_description="Tests for various fxed issues and regressions." test_description="Tests for various fixed issues and regressions."
. lib/test-lib.sh . lib/test-lib.sh
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论