提交 b6aad53d 作者: Matt Bell 提交者: Juan Batiz-Benet

core/commands2: Added 'version' command

上级 af65eec2
......@@ -65,6 +65,7 @@ var rootSubcommands = map[string]*cmds.Command{
"diag": diagCmd,
"pin": pinCmd,
"unpin": unpinCmd,
"version": versionCmd,
// test subcommands
// TODO: remove these when we don't need them anymore
......
package commands
import (
"errors"
cmds "github.com/jbenet/go-ipfs/commands"
config "github.com/jbenet/go-ipfs/config"
)
type VersionOutput struct {
Version string
}
var versionCmd = &cmds.Command{
Options: []cmds.Option{
cmds.Option{[]string{"number", "n"}, cmds.Bool},
},
Help: `ipfs version - Show ipfs version information.
Returns the current version of ipfs and exits.
`,
Run: func(res cmds.Response, req cmds.Request) {
res.SetOutput(&VersionOutput{
Version: config.CurrentVersionNumber,
})
},
Marshallers: map[cmds.EncodingType]cmds.Marshaller{
cmds.Text: func(res cmds.Response) ([]byte, error) {
v := res.Output().(*VersionOutput)
s := ""
opt, found := res.Request().Option("number")
number, ok := opt.(bool)
if found && !ok {
return nil, errors.New("cast error")
}
if !number {
s += "ipfs version "
}
s += v.Version
return []byte(s), nil
},
},
Type: &VersionOutput{},
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论