-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
45 lines (39 loc) · 1.02 KB
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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{},
}