Updated the printing to follow the new specs
This commit is contained in:
parent
f144050535
commit
66f1bc01a2
25
common.go
25
common.go
@ -5,6 +5,7 @@ package jsh
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
type JshFrame struct {
|
||||
@ -22,22 +23,44 @@ func (j JshFrame) ToJson() *string {
|
||||
return &jsonString
|
||||
}
|
||||
|
||||
func (j JshFrame) StdOutToJson() *string {
|
||||
jsonOut, err := json.Marshal(j.StdOut)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
jsonString := string(jsonOut)
|
||||
return &jsonString
|
||||
}
|
||||
|
||||
func (j JshFrame) StdErrToJson() *string {
|
||||
jsonOut, err := json.Marshal(j.StdErr)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
jsonString := string(jsonOut)
|
||||
return &jsonString
|
||||
}
|
||||
|
||||
// goroutine for outputing frames. Pass it a channel of pointers to JshFrames,
|
||||
// and it will send "true" to the done channel once you close the queue channel.
|
||||
func OutputFrames(queue chan *JshFrame, done chan bool) {
|
||||
fmt.Printf("[")
|
||||
fmt.Fprintf(os.Stderr, "[")
|
||||
isFirst := true
|
||||
for {
|
||||
frame, more := <-queue
|
||||
if more {
|
||||
if !isFirst {
|
||||
fmt.Printf(",")
|
||||
fmt.Fprintf(os.Stderr, ",")
|
||||
} else {
|
||||
isFirst = false
|
||||
}
|
||||
fmt.Printf(*frame.ToJson())
|
||||
fmt.Printf(*frame.StdOutToJson())
|
||||
fmt.Fprintf(os.Stderr, *frame.StdErrToJson())
|
||||
} else {
|
||||
fmt.Printf("]\n")
|
||||
fmt.Fprintf(os.Stderr, "]\n")
|
||||
done <- true
|
||||
return
|
||||
}
|
||||
|
@ -48,17 +48,17 @@ func main() {
|
||||
root := "." //flag.Arg(0)
|
||||
dir, _ := ioutil.ReadDir(root)
|
||||
|
||||
fmt.Printf("[{\"StdOut\": [\n")
|
||||
fmt.Printf("[\n")
|
||||
|
||||
if !a_flag {
|
||||
for _, entry := range dir {
|
||||
if entry.Name()[0] != '.' {
|
||||
if !first {
|
||||
fmt.Printf(",")
|
||||
fmt.Printf(",\n")
|
||||
} else {
|
||||
first = false
|
||||
}
|
||||
fmt.Printf("%s\n", get_fileinfo(entry.Name(), size_flag, mode_flag, inode_flag))
|
||||
fmt.Printf("%s", get_fileinfo(entry.Name(), size_flag, mode_flag, inode_flag))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -71,5 +71,5 @@ func main() {
|
||||
fmt.Printf("%s\n", get_fileinfo(entry.Name(), size_flag, mode_flag, inode_flag))
|
||||
}
|
||||
}
|
||||
fmt.Printf("], \"StdErr\": []}]\n")
|
||||
fmt.Printf("\n]\n")
|
||||
}
|
||||
|
Reference in New Issue
Block a user