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 (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type JshFrame struct {
|
type JshFrame struct {
|
||||||
@ -22,22 +23,44 @@ func (j JshFrame) ToJson() *string {
|
|||||||
return &jsonString
|
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,
|
// 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.
|
// and it will send "true" to the done channel once you close the queue channel.
|
||||||
func OutputFrames(queue chan *JshFrame, done chan bool) {
|
func OutputFrames(queue chan *JshFrame, done chan bool) {
|
||||||
fmt.Printf("[")
|
fmt.Printf("[")
|
||||||
|
fmt.Fprintf(os.Stderr, "[")
|
||||||
isFirst := true
|
isFirst := true
|
||||||
for {
|
for {
|
||||||
frame, more := <-queue
|
frame, more := <-queue
|
||||||
if more {
|
if more {
|
||||||
if !isFirst {
|
if !isFirst {
|
||||||
fmt.Printf(",")
|
fmt.Printf(",")
|
||||||
|
fmt.Fprintf(os.Stderr, ",")
|
||||||
} else {
|
} else {
|
||||||
isFirst = false
|
isFirst = false
|
||||||
}
|
}
|
||||||
fmt.Printf(*frame.ToJson())
|
fmt.Printf(*frame.StdOutToJson())
|
||||||
|
fmt.Fprintf(os.Stderr, *frame.StdErrToJson())
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("]\n")
|
fmt.Printf("]\n")
|
||||||
|
fmt.Fprintf(os.Stderr, "]\n")
|
||||||
done <- true
|
done <- true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,17 +48,17 @@ func main() {
|
|||||||
root := "." //flag.Arg(0)
|
root := "." //flag.Arg(0)
|
||||||
dir, _ := ioutil.ReadDir(root)
|
dir, _ := ioutil.ReadDir(root)
|
||||||
|
|
||||||
fmt.Printf("[{\"StdOut\": [\n")
|
fmt.Printf("[\n")
|
||||||
|
|
||||||
if !a_flag {
|
if !a_flag {
|
||||||
for _, entry := range dir {
|
for _, entry := range dir {
|
||||||
if entry.Name()[0] != '.' {
|
if entry.Name()[0] != '.' {
|
||||||
if !first {
|
if !first {
|
||||||
fmt.Printf(",")
|
fmt.Printf(",\n")
|
||||||
} else {
|
} else {
|
||||||
first = false
|
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 {
|
} else {
|
||||||
@ -71,5 +71,5 @@ func main() {
|
|||||||
fmt.Printf("%s\n", get_fileinfo(entry.Name(), size_flag, mode_flag, inode_flag))
|
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