Skip to content

Commit

Permalink
add option to version command to print repo version
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
whyrusleeping committed Nov 3, 2015

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent b508c23 commit 7811983
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions core/commands/version.go
Original file line number Diff line number Diff line change
@@ -7,11 +7,13 @@ import (

cmds "github.com/ipfs/go-ipfs/commands"
config "github.com/ipfs/go-ipfs/repo/config"
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
)

type VersionOutput struct {
Version string
Commit string
Commit string
Repo string
}

var VersionCmd = &cmds.Command{
@@ -23,17 +25,28 @@ var VersionCmd = &cmds.Command{
Options: []cmds.Option{
cmds.BoolOption("number", "n", "Only show the version number"),
cmds.BoolOption("commit", "Show the commit hash"),
cmds.BoolOption("repo", "Show repo version"),
},
Run: func(req cmds.Request, res cmds.Response) {
res.SetOutput(&VersionOutput{
Version: config.CurrentVersionNumber,
Commit: config.CurrentCommit,
Commit: config.CurrentCommit,
Repo: fsrepo.RepoVersion,
})
},
Marshalers: cmds.MarshalerMap{
cmds.Text: func(res cmds.Response) (io.Reader, error) {
v := res.Output().(*VersionOutput)

repo, _, err := res.Request().Option("repo").Bool()
if err != nil {
return nil, err
}

if repo {
return strings.NewReader(v.Repo + "\n"), nil
}

commit, found, err := res.Request().Option("commit").Bool()
commitTxt := ""
if err != nil {

0 comments on commit 7811983

Please sign in to comment.