Skip to content

Commit 7811983

Browse files
committedNov 3, 2015
add option to version command to print repo version
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
1 parent b508c23 commit 7811983

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed
 

‎core/commands/version.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import (
77

88
cmds "github.com/ipfs/go-ipfs/commands"
99
config "github.com/ipfs/go-ipfs/repo/config"
10+
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
1011
)
1112

1213
type VersionOutput struct {
1314
Version string
14-
Commit string
15+
Commit string
16+
Repo string
1517
}
1618

1719
var VersionCmd = &cmds.Command{
@@ -23,17 +25,28 @@ var VersionCmd = &cmds.Command{
2325
Options: []cmds.Option{
2426
cmds.BoolOption("number", "n", "Only show the version number"),
2527
cmds.BoolOption("commit", "Show the commit hash"),
28+
cmds.BoolOption("repo", "Show repo version"),
2629
},
2730
Run: func(req cmds.Request, res cmds.Response) {
2831
res.SetOutput(&VersionOutput{
2932
Version: config.CurrentVersionNumber,
30-
Commit: config.CurrentCommit,
33+
Commit: config.CurrentCommit,
34+
Repo: fsrepo.RepoVersion,
3135
})
3236
},
3337
Marshalers: cmds.MarshalerMap{
3438
cmds.Text: func(res cmds.Response) (io.Reader, error) {
3539
v := res.Output().(*VersionOutput)
3640

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+
3750
commit, found, err := res.Request().Option("commit").Bool()
3851
commitTxt := ""
3952
if err != nil {

0 commit comments

Comments
 (0)
Please sign in to comment.