github.com/keltia/go-ipfs@v0.3.8-0.20150909044612-210793031c63/core/commands/version.go (about) 1 package commands 2 3 import ( 4 "fmt" 5 "io" 6 "strings" 7 8 cmds "github.com/ipfs/go-ipfs/commands" 9 config "github.com/ipfs/go-ipfs/repo/config" 10 ) 11 12 type VersionOutput struct { 13 Version string 14 } 15 16 var VersionCmd = &cmds.Command{ 17 Helptext: cmds.HelpText{ 18 Tagline: "Shows ipfs version information", 19 ShortDescription: "Returns the current version of ipfs and exits.", 20 }, 21 22 Options: []cmds.Option{ 23 cmds.BoolOption("number", "n", "Only show the version number"), 24 }, 25 Run: func(req cmds.Request, res cmds.Response) { 26 res.SetOutput(&VersionOutput{ 27 Version: config.CurrentVersionNumber, 28 }) 29 }, 30 Marshalers: cmds.MarshalerMap{ 31 cmds.Text: func(res cmds.Response) (io.Reader, error) { 32 v := res.Output().(*VersionOutput) 33 34 number, found, err := res.Request().Option("number").Bool() 35 if err != nil { 36 return nil, err 37 } 38 if found && number { 39 return strings.NewReader(fmt.Sprintln(v.Version)), nil 40 } 41 return strings.NewReader(fmt.Sprintf("ipfs version %s\n", v.Version)), nil 42 }, 43 }, 44 Type: VersionOutput{}, 45 }