@cryptotaxi247 / kubo / commits / 781198390

add option to version command to print repo version

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Jeromy committed Nov 3, 2015 at 12:19 UTC 781198390138ea415e6c090a5f18846fa55987a5
1 file changed +15 -2
core/commands/version.go
+15 -2
@@ -7,11 +7,13 @@ import (
7
8 cmds "github.com/ipfs/go-ipfs/commands"
9 config "github.com/ipfs/go-ipfs/repo/config"
10 + fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
11 )
12
13 type VersionOutput struct {
14 Version string
14 - Commit string
15 + Commit string
16 + Repo string
17 }
18
19 var VersionCmd = &cmds.Command{
@@ -23,17 +25,28 @@ var VersionCmd = &cmds.Command{
25 Options: []cmds.Option{
26 cmds.BoolOption("number", "n", "Only show the version number"),
27 cmds.BoolOption("commit", "Show the commit hash"),
28 + cmds.BoolOption("repo", "Show repo version"),
29 },
30 Run: func(req cmds.Request, res cmds.Response) {
31 res.SetOutput(&VersionOutput{
32 Version: config.CurrentVersionNumber,
30 - Commit: config.CurrentCommit,
33 + Commit: config.CurrentCommit,
34 + Repo: fsrepo.RepoVersion,
35 })
36 },
37 Marshalers: cmds.MarshalerMap{
38 cmds.Text: func(res cmds.Response) (io.Reader, error) {
39 v := res.Output().(*VersionOutput)
40
41 + repo, _, err := res.Request().Option("repo").Bool()
42 + if err != nil {
43 + return nil, err
44 + }
45 +
46 + if repo {
47 + return strings.NewReader(v.Repo + "\n"), nil
48 + }
49 +
50 commit, found, err := res.Request().Option("commit").Bool()
51 commitTxt := ""
52 if err != nil {