version.go 997 Bytes
Newer Older
1 2 3
package commands

import (
Brian Tiger Chow's avatar
Brian Tiger Chow committed
4 5
	"fmt"

6 7 8 9 10 11 12 13
	cmds "github.com/jbenet/go-ipfs/commands"
	config "github.com/jbenet/go-ipfs/config"
)

type VersionOutput struct {
	Version string
}

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
14
var VersionCmd = &cmds.Command{
15
	Helptext: cmds.HelpText{
Brian Tiger Chow's avatar
Brian Tiger Chow committed
16
		Tagline:          "Shows ipfs version information",
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
17
		ShortDescription: "Returns the current version of ipfs and exits.",
18
	},
19

20
	Options: []cmds.Option{
Brian Tiger Chow's avatar
Brian Tiger Chow committed
21
		cmds.BoolOption("number", "n", "Only show the version number"),
22
	},
23 24
	Run: func(req cmds.Request) (interface{}, error) {
		return &VersionOutput{
25
			Version: config.CurrentVersionNumber,
26
		}, nil
27
	},
28
	Marshalers: cmds.MarshalerMap{
29 30 31
		cmds.Text: func(res cmds.Response) ([]byte, error) {
			v := res.Output().(*VersionOutput)

32 33 34 35
			number, found, err := res.Request().Option("number").Bool()
			if err != nil {
				return nil, err
			}
Brian Tiger Chow's avatar
Brian Tiger Chow committed
36 37
			if found && number {
				return []byte(fmt.Sprintln(v.Version)), nil
38
			}
Brian Tiger Chow's avatar
Brian Tiger Chow committed
39
			return []byte(fmt.Sprintf("ipfs version %s\n", v.Version)), nil
40 41 42 43
		},
	},
	Type: &VersionOutput{},
}