Skip to content

Commit

Permalink
Added long json formatted output for text encoding on inspect command
Browse files Browse the repository at this point in the history
  • Loading branch information
rosalinekarr committed May 8, 2019
1 parent b6f9007 commit db441db
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions commands/inspector.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package commands

import (
"encoding/json"
"io"
"os"
"runtime"

Expand Down Expand Up @@ -53,6 +55,19 @@ Prints out information about filecoin process and its environment.
allInfo.FilecoinVersion = GetInspectorAPI(env).FilecoinVersion()
return cmds.EmitOnce(res, allInfo)
},
Type: AllInspectorInfo{},
Encoders: cmds.EncoderMap{
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, info *AllInspectorInfo) error {
marshaled, err := json.MarshalIndent(info, "", "\t")
if err != nil {
return err
}
marshaled = append(marshaled, byte('\n'))

_, err = w.Write(marshaled)
return err
}),
},
}

var runtimeInspectCmd = &cmds.Command{
Expand All @@ -66,6 +81,19 @@ Prints out information about the golang runtime.
out := GetInspectorAPI(env).Runtime()
return cmds.EmitOnce(res, out)
},
Type: RuntimeInfo{},
Encoders: cmds.EncoderMap{
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, info *RuntimeInfo) error {
marshaled, err := json.MarshalIndent(info, "", "\t")
if err != nil {
return err
}
marshaled = append(marshaled, byte('\n'))

_, err = w.Write(marshaled)
return err
}),
},
}

var diskInspectCmd = &cmds.Command{
Expand All @@ -82,6 +110,19 @@ Prints out information about the filesystem.
}
return cmds.EmitOnce(res, out)
},
Type: DiskInfo{},
Encoders: cmds.EncoderMap{
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, info *DiskInfo) error {
marshaled, err := json.MarshalIndent(info, "", "\t")
if err != nil {
return err
}
marshaled = append(marshaled, byte('\n'))

_, err = w.Write(marshaled)
return err
}),
},
}

var memoryInspectCmd = &cmds.Command{
Expand All @@ -98,6 +139,19 @@ Prints out information about memory usage.
}
return cmds.EmitOnce(res, out)
},
Type: MemoryInfo{},
Encoders: cmds.EncoderMap{
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, info *MemoryInfo) error {
marshaled, err := json.MarshalIndent(info, "", "\t")
if err != nil {
return err
}
marshaled = append(marshaled, byte('\n'))

_, err = w.Write(marshaled)
return err
}),
},
}

var configInspectCmd = &cmds.Command{
Expand All @@ -111,6 +165,19 @@ Prints out information about your filecoin nodes config.
out := GetInspectorAPI(env).Config()
return cmds.EmitOnce(res, out)
},
Type: config.Config{},
Encoders: cmds.EncoderMap{
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, info *config.Config) error {
marshaled, err := json.MarshalIndent(info, "", "\t")
if err != nil {
return err
}
marshaled = append(marshaled, byte('\n'))

_, err = w.Write(marshaled)
return err
}),
},
}

var envInspectCmd = &cmds.Command{
Expand All @@ -124,6 +191,19 @@ Prints out information about your filecoin nodes environment.
out := GetInspectorAPI(env).Environment()
return cmds.EmitOnce(res, out)
},
Type: EnvironmentInfo{},
Encoders: cmds.EncoderMap{
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, info *EnvironmentInfo) error {
marshaled, err := json.MarshalIndent(info, "", "\t")
if err != nil {
return err
}
marshaled = append(marshaled, byte('\n'))

_, err = w.Write(marshaled)
return err
}),
},
}

// NewInspectorAPI returns a `Inspector` used to inspect the go-filecoin node.
Expand Down

0 comments on commit db441db

Please sign in to comment.