From 781198390138ea415e6c090a5f18846fa55987a5 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Tue, 3 Nov 2015 12:19:12 -0800 Subject: [PATCH] add option to version command to print repo version License: MIT Signed-off-by: Jeromy --- core/commands/version.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/core/commands/version.go b/core/commands/version.go index 2c3bafe07..7f18daed2 100644 --- a/core/commands/version.go +++ b/core/commands/version.go @@ -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 {