Skip to content

Commit

Permalink
Feat/better inspect output 2720 (#2730)
Browse files Browse the repository at this point in the history
* Added long json formatted output for text encoding on inspect command

* Updated test encoders for all inspect commands to look better

* Moved config printing to the end of the inspect all command
  • Loading branch information
rosalinekarr authored May 10, 2019
1 parent 9508e3d commit dcb0be3
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 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,53 @@ 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 {
sw := NewSilentWriter(w)

// Print Version
sw.Printf("Version:\t%s\n", info.FilecoinVersion)

// Print Runtime Info
sw.Printf("\nRuntime\n")
sw.Printf("OS: \t%s\n", info.Runtime.OS)
sw.Printf("Arch: \t%s\n", info.Runtime.Arch)
sw.Printf("Version: \t%s\n", info.Runtime.Version)
sw.Printf("Compiler: \t%s\n", info.Runtime.Compiler)
sw.Printf("NumProc: \t%d\n", info.Runtime.NumProc)
sw.Printf("GoMaxProcs: \t%d\n", info.Runtime.GoMaxProcs)
sw.Printf("NumGoRoutines:\t%d\n", info.Runtime.NumGoRoutines)
sw.Printf("NumCGoCalls: \t%d\n", info.Runtime.NumCGoCalls)

// Print Disk Info
sw.Printf("\nDisk\n")
sw.Printf("Free: \t%d\n", info.Disk.Free)
sw.Printf("Total: \t%d\n", info.Disk.Total)
sw.Printf("FSType:\t%s\n", info.Disk.FSType)

// Print Memory Info
sw.Printf("\nMemory\n")
sw.Printf("Swap: \t%d\n", info.Memory.Swap)
sw.Printf("Virtual:\t%d\n", info.Memory.Virtual)

// Print Environment Info
sw.Printf("\nEnvironment\n")
sw.Printf("FilAPI: \t%s\n", info.Environment.FilAPI)
sw.Printf("FilPath:\t%s\n", info.Environment.FilPath)
sw.Printf("GoPath: \t%s\n", info.Environment.GoPath)

// Print Config Info
sw.Printf("\nConfig\n")
marshaled, err := json.MarshalIndent(info.Config, "", "\t")
if err != nil {
return err
}
sw.Printf("%s\n", marshaled)

return sw.Error()
}),
},
}

var runtimeInspectCmd = &cmds.Command{
Expand All @@ -66,6 +115,21 @@ 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 {
sw := NewSilentWriter(w)
sw.Printf("OS: \t%s\n", info.OS)
sw.Printf("Arch: \t%s\n", info.Arch)
sw.Printf("Version: \t%s\n", info.Version)
sw.Printf("Compiler: \t%s\n", info.Compiler)
sw.Printf("NumProc: \t%d\n", info.NumProc)
sw.Printf("GoMaxProcs: \t%d\n", info.GoMaxProcs)
sw.Printf("NumGoRoutines:\t%d\n", info.NumGoRoutines)
sw.Printf("NumCGoCalls: \t%d\n", info.NumCGoCalls)
return sw.Error()
}),
},
}

var diskInspectCmd = &cmds.Command{
Expand All @@ -82,6 +146,16 @@ 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 {
sw := NewSilentWriter(w)
sw.Printf("Free: \t%d\n", info.Free)
sw.Printf("Total: \t%d\n", info.Total)
sw.Printf("FSType:\t%s\n", info.FSType)
return sw.Error()
}),
},
}

var memoryInspectCmd = &cmds.Command{
Expand All @@ -98,6 +172,15 @@ 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 {
sw := NewSilentWriter(w)
sw.Printf("Swap: \t%d\n", info.Swap)
sw.Printf("Virtual:\t%d\n", info.Virtual)
return sw.Error()
}),
},
}

var configInspectCmd = &cmds.Command{
Expand All @@ -111,6 +194,18 @@ 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 +219,16 @@ 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 {
sw := NewSilentWriter(w)
sw.Printf("FilAPI: \t%s\n", info.FilAPI)
sw.Printf("FilPath:\t%s\n", info.FilPath)
sw.Printf("GoPath: \t%s\n", info.GoPath)
return sw.Error()
}),
},
}

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

0 comments on commit dcb0be3

Please sign in to comment.