1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-28 08:47:42 +08:00
Files
kubo/core/commands/version.go
Ho-Sheng Hsiao bf22aeec0a Reorged imports from jbenet/go-ipfs to ipfs/go-ipfs
- Modified Godeps/Godeps.json by hand
- [TEST] Updated welcome docs hash to sharness
- [TEST] Updated contact doc
- [TEST] disabled breaking test (t0080-repo refs local)
2015-03-31 12:52:25 -07:00

46 lines
1.0 KiB
Go

package commands
import (
"fmt"
"io"
"strings"
cmds "github.com/ipfs/go-ipfs/commands"
config "github.com/ipfs/go-ipfs/repo/config"
)
type VersionOutput struct {
Version string
}
var VersionCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Shows ipfs version information",
ShortDescription: "Returns the current version of ipfs and exits.",
},
Options: []cmds.Option{
cmds.BoolOption("number", "n", "Only show the version number"),
},
Run: func(req cmds.Request, res cmds.Response) {
res.SetOutput(&VersionOutput{
Version: config.CurrentVersionNumber,
})
},
Marshalers: cmds.MarshalerMap{
cmds.Text: func(res cmds.Response) (io.Reader, error) {
v := res.Output().(*VersionOutput)
number, found, err := res.Request().Option("number").Bool()
if err != nil {
return nil, err
}
if found && number {
return strings.NewReader(fmt.Sprintln(v.Version)), nil
}
return strings.NewReader(fmt.Sprintf("ipfs version %s\n", v.Version)), nil
},
},
Type: VersionOutput{},
}