mirror of
https://github.com/ipfs/kubo.git
synced 2025-08-06 19:44:01 +08:00
Adds repo version subcommand
Fixes #2571 License: MIT Signed-off-by: Mike Pfister <pfista@gmail.com>
This commit is contained in:
@ -7,12 +7,17 @@ import (
|
|||||||
corerepo "github.com/ipfs/go-ipfs/core/corerepo"
|
corerepo "github.com/ipfs/go-ipfs/core/corerepo"
|
||||||
config "github.com/ipfs/go-ipfs/repo/config"
|
config "github.com/ipfs/go-ipfs/repo/config"
|
||||||
lockfile "github.com/ipfs/go-ipfs/repo/fsrepo/lock"
|
lockfile "github.com/ipfs/go-ipfs/repo/fsrepo/lock"
|
||||||
|
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
|
||||||
u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
|
u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type RepoVersion struct {
|
||||||
|
Version string
|
||||||
|
}
|
||||||
|
|
||||||
var RepoCmd = &cmds.Command{
|
var RepoCmd = &cmds.Command{
|
||||||
Helptext: cmds.HelpText{
|
Helptext: cmds.HelpText{
|
||||||
Tagline: "Manipulate the IPFS repo.",
|
Tagline: "Manipulate the IPFS repo.",
|
||||||
@ -25,6 +30,7 @@ var RepoCmd = &cmds.Command{
|
|||||||
"gc": repoGcCmd,
|
"gc": repoGcCmd,
|
||||||
"stat": repoStatCmd,
|
"stat": repoStatCmd,
|
||||||
"fsck": RepoFsckCmd,
|
"fsck": RepoFsckCmd,
|
||||||
|
"version": repoVersionCmd,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,5 +214,40 @@ daemons are running.
|
|||||||
Type: MessageOutput{},
|
Type: MessageOutput{},
|
||||||
Marshalers: cmds.MarshalerMap{
|
Marshalers: cmds.MarshalerMap{
|
||||||
cmds.Text: MessageTextMarshaler,
|
cmds.Text: MessageTextMarshaler,
|
||||||
|
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
|
||||||
|
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user