@cryptotaxi247 / kubo / commits / b6aad53d8

core/commands2: Added 'version' command

Matt Bell committed Nov 5, 2014 at 02:17 UTC b6aad53d86a5b1971e3816dcd5d22f9e8315df49
2 files changed +47
core/commands2/root.go
+1
@@ -65,6 +65,7 @@ var rootSubcommands = map[string]*cmds.Command{
65 "diag": diagCmd,
66 "pin": pinCmd,
67 "unpin": unpinCmd,
68 + "version": versionCmd,
69
70 // test subcommands
71 // TODO: remove these when we don't need them anymore
core/commands2/version.go new
+46
@@ -0,0 +1,46 @@
1 +package commands
2 +
3 +import (
4 + "errors"
5 +
6 + cmds "github.com/jbenet/go-ipfs/commands"
7 + config "github.com/jbenet/go-ipfs/config"
8 +)
9 +
10 +type VersionOutput struct {
11 + Version string
12 +}
13 +
14 +var versionCmd = &cmds.Command{
15 + Options: []cmds.Option{
16 + cmds.Option{[]string{"number", "n"}, cmds.Bool},
17 + },
18 + Help: `ipfs version - Show ipfs version information.
19 +
20 + Returns the current version of ipfs and exits.
21 + `,
22 + Run: func(res cmds.Response, req cmds.Request) {
23 + res.SetOutput(&VersionOutput{
24 + Version: config.CurrentVersionNumber,
25 + })
26 + },
27 + Marshallers: map[cmds.EncodingType]cmds.Marshaller{
28 + cmds.Text: func(res cmds.Response) ([]byte, error) {
29 + v := res.Output().(*VersionOutput)
30 + s := ""
31 +
32 + opt, found := res.Request().Option("number")
33 + number, ok := opt.(bool)
34 + if found && !ok {
35 + return nil, errors.New("cast error")
36 + }
37 +
38 + if !number {
39 + s += "ipfs version "
40 + }
41 + s += v.Version
42 + return []byte(s), nil
43 + },
44 + },
45 + Type: &VersionOutput{},
46 +}