-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.go
43 lines (34 loc) · 839 Bytes
/
info.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
package subcommand
import (
"errors"
"github.com/sean9999/go-flargs"
"github.com/sean9999/go-oracle"
)
var lineBreak = []byte("\n")
// Info outputs public information about oneself.
func Info(env *flargs.Environment, globals *ParamSet, _ []string) error {
if globals.Config == nil {
return errors.New("config is nil")
}
globals.Config.Seek(0, 0)
me, err := oracle.From(globals.Config)
if err != nil {
return err
}
j, err := me.AsPeer().MarshalJSON()
if err != nil {
return err
}
env.OutputStream.Write(j)
env.OutputStream.Write(lineBreak)
if len(me.Peers()) > 0 {
env.OutputStream.Write(lineBreak)
env.OutputStream.Write([]byte("peers"))
env.OutputStream.Write(lineBreak)
for nick := range me.Peers() {
env.OutputStream.Write([]byte(nick))
env.OutputStream.Write(lineBreak)
}
}
return nil
}