Add helptext, default logic to `ipfs stats`
I've added: Synopsis, shortDescription, and longDescription for stats and stats bw. I also added default(false) for poll and default("1s") for interval, and modified the logic to make it fit. Part of #2484 and #2647. License: MIT Signed-off-by: Richard Littauer <richard.littauer@gmail.com>
Richard Littauer committed
May 12, 2016 at 13:17 UTC
8ee399fbebf51cfe77dc35ccb7c9ba6a8b89d0eb
1 file changed
+47
-14
core/commands/stat.go
+47
-14
@@ -18,8 +18,10 @@ import (
18
19
var StatsCmd = &cmds.Command{
20
Helptext: cmds.HelpText{
21
- Tagline: "Query IPFS statistics.",
22
- ShortDescription: ``,
21
+ Tagline: "Query ipfs statistics.",
22
+ Synopsis: "ipfs stats <command>",
23
+ ShortDescription: `'ipfs stats' is a set of commands to help look at statistics for your ipfs node.`,
24
+ LongDescription: `'ipfs stats' is a set of commands to help look at statistics for your ipfs node.`,
25
},
26
27
Subcommands: map[string]*cmds.Command{
@@ -30,13 +32,48 @@ var StatsCmd = &cmds.Command{
32
var statBwCmd = &cmds.Command{
33
Helptext: cmds.HelpText{
34
Tagline: "Print ipfs bandwidth information.",
33
- ShortDescription: ``,
35
+ Synopsis: "ipfs stats bw [--peer <peerId> | -p] [--proto <protocol> | -t] [--poll] [--interval <timeInterval> | -i]",
36
+ ShortDescription: `'ipfs stats bw' prints bandwidth information for the ipfs daemon.
37
+It displays: TotalIn, TotalOut, RateIn, RateOut.
38
+ `,
39
+ LongDescription: `'ipfs stats bw' prints bandwidth information for the ipfs daemon.
40
+It displays: TotalIn, TotalOut, RateIn, RateOut.
41
+
42
+By default, overall bandwidth and all protocols are shown. To limit bandwidth to
43
+a particular peer, use the 'peer' option along with that peer's multihash id. To
44
+specify a specific protocol, use the 'proto' option. The 'peer' and 'proto'
45
+options cannot be specified simultaneously. The protocols that be queried using
46
+this method are outlined in the specification: https://github.com/ipfs/specs/blob/master/libp2p/7-properties.md#757-protocol-multicodecs
47
+
48
+Example protocol options:
49
+ - /ipfs/id/1.0.0
50
+ - /ipfs/bitswap
51
+ - /ipfs/dht
52
+
53
+Example:
54
+
55
+ > ipfs stats bw -t /ipfs/bitswap
56
+ Bandwidth
57
+ TotalIn: 5.0MB
58
+ TotalOut: 0B
59
+ RateIn: 343B/s
60
+ RateOut: 0B/s
61
+ > ipfs stats bw -p QmepgFW7BHEtU4pZJdxaNiv75mKLLRQnPi1KaaXmQN4V1a
62
+ Bandwidth
63
+ TotalIn: 4.9MB
64
+ TotalOut: 12MB
65
+ RateIn: 0B/s
66
+ RateOut: 0B/s
67
+`,
68
},
69
Options: []cmds.Option{
70
cmds.StringOption("peer", "p", "Specify a peer to print bandwidth for."),
71
cmds.StringOption("proto", "t", "Specify a protocol to print bandwidth for."),
38
- cmds.BoolOption("poll", "Print bandwidth at an interval. Default: false."),
39
- cmds.StringOption("interval", "i", "Time interval to wait between updating output, if 'poll' is true."),
72
+ cmds.BoolOption("poll", "Print bandwidth at an interval.").Default(false),
73
+ cmds.StringOption("interval", "i", `Time interval to wait between updating output, if 'poll' is true.
74
+
75
+ This accepts durations such as "300s", "1.5h" or "2h45m". Valid time units are:
76
+ "ns", "us" (or "µs"), "ms", "s", "m", "h".`).Default("1s"),
77
},
78
79
Run: func(req cmds.Request, res cmds.Response) {
@@ -78,19 +115,15 @@ var statBwCmd = &cmds.Command{
115
pid = checkpid
116
}
117
81
- interval := time.Second
82
- timeS, found, err := req.Option("interval").String()
118
+ timeS, _, err := req.Option("interval").String()
119
if err != nil {
120
res.SetError(err, cmds.ErrNormal)
121
return
122
}
87
- if found {
88
- v, err := time.ParseDuration(timeS)
89
- if err != nil {
90
- res.SetError(err, cmds.ErrNormal)
91
- return
92
- }
93
- interval = v
123
+ interval, err := time.ParseDuration(timeS)
124
+ if err != nil {
125
+ res.SetError(err, cmds.ErrNormal)
126
+ return
127
}
128
129
doPoll, _, err := req.Option("poll").Bool()