@cryptotaxi247 / kubo / commits / cd0a33c7c

Adds repo version subcommand

Fixes #2571 License: MIT Signed-off-by: Mike Pfister <pfista@gmail.com>

Michael Pfister committed Apr 20, 2016 at 19:41 UTC cd0a33c7c29de0b36636a4897c812bff6ea5cc00
1 file changed +41
core/commands/repo.go
+41
@@ -7,12 +7,17 @@ import (
7 corerepo "github.com/ipfs/go-ipfs/core/corerepo"
8 config "github.com/ipfs/go-ipfs/repo/config"
9 lockfile "github.com/ipfs/go-ipfs/repo/fsrepo/lock"
10 + fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
11 u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
12 "io"
13 "os"
14 "path/filepath"
15 )
16
17 +type RepoVersion struct {
18 + Version string
19 +}
20 +
21 var RepoCmd = &cmds.Command{
22 Helptext: cmds.HelpText{
23 Tagline: "Manipulate the IPFS repo.",
@@ -25,6 +30,7 @@ var RepoCmd = &cmds.Command{
30 "gc": repoGcCmd,
31 "stat": repoStatCmd,
32 "fsck": RepoFsckCmd,
33 + "version": repoVersionCmd,
34 },
35 }
36
@@ -208,5 +214,40 @@ daemons are running.
214 Type: MessageOutput{},
215 Marshalers: cmds.MarshalerMap{
216 cmds.Text: MessageTextMarshaler,
217 +var repoVersionCmd = &cmds.Command{
218 + Helptext: cmds.HelpText{
219 + Tagline: "Show the repo version.",
220 + ShortDescription: `
221 +'ipfs repo version' returns the current repo version.
222 +`,
223 + },
224 +
225 + Options: []cmds.Option{
226 + cmds.BoolOption("quiet", "q", "Write minimal output."),
227 + },
228 + Run: func(req cmds.Request, res cmds.Response) {
229 + res.SetOutput(&RepoVersion{
230 + Version: fsrepo.RepoVersion,
231 + })
232 + },
233 + Type: RepoVersion{},
234 + Marshalers: cmds.MarshalerMap{
235 + cmds.Text: func(res cmds.Response) (io.Reader, error) {
236 + response := res.Output().(*RepoVersion)
237 +
238 + quiet, _, err := res.Request().Option("quiet").Bool()
239 + if err != nil {
240 + return nil, err
241 + }
242 +
243 + buf := new(bytes.Buffer)
244 + if quiet {
245 + buf = bytes.NewBufferString(fmt.Sprintf("fs-repo@%s\n", response.Version))
246 + } else {
247 + buf = bytes.NewBufferString(fmt.Sprintf("ipfs repo version fs-repo@%s\n", response.Version))
248 + }
249 + return buf, nil
250 +
251 + },
252 },
253 }