1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-26 23:53:19 +08:00

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

Add version --all option
This commit is contained in:
Jeromy Johnson
2016-06-02 12:23:45 -07:00
4 changed files with 27 additions and 2 deletions

View File

@ -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 {
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{
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{
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
}, },
}, },

View File

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

View File

@ -1,6 +1,6 @@
#!/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

View File

@ -1,6 +1,6 @@
#!/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