Skip to content

Commit

Permalink
Adds repo version subcommand
Browse files Browse the repository at this point in the history
Fixes ipfs#2571

License: MIT
Signed-off-by: Mike Pfister <pfista@gmail.com>
  • Loading branch information
pfista committed Apr 21, 2016
1 parent 8e2fcbe commit 07638d6
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions core/commands/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ import (
"fmt"
cmds "github.com/ipfs/go-ipfs/commands"
corerepo "github.com/ipfs/go-ipfs/core/corerepo"
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
"io"
)

type RepoVersion struct {
Version string
}

var RepoCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Manipulate the IPFS repo.",
Expand All @@ -18,8 +23,9 @@ var RepoCmd = &cmds.Command{
},

Subcommands: map[string]*cmds.Command{
"gc": repoGcCmd,
"stat": repoStatCmd,
"gc": repoGcCmd,
"stat": repoStatCmd,
"version": repoVersionCmd,
},
}

Expand Down Expand Up @@ -154,3 +160,41 @@ Version string The repo version
},
},
}

var repoVersionCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Show the repo version.",
ShortDescription: `
'ipfs repo version' returns the current repo version.
`,
},

Options: []cmds.Option{
cmds.BoolOption("quiet", "q", "Write minimal output."),
},
Run: func(req cmds.Request, res cmds.Response) {
res.SetOutput(&RepoVersion{
Version: fsrepo.RepoVersion,
})
},
Type: RepoVersion{},
Marshalers: cmds.MarshalerMap{
cmds.Text: func(res cmds.Response) (io.Reader, error) {
response := res.Output().(*RepoVersion)

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

buf := new(bytes.Buffer)
if quiet {
buf = bytes.NewBufferString(fmt.Sprintf("fs-repo@%s\n", response.Version))
} else {
buf = bytes.NewBufferString(fmt.Sprintf("ipfs repo version fs-repo@%s\n", response.Version))
}
return buf, nil

},
},
}

0 comments on commit 07638d6

Please sign in to comment.