This commit is contained in:
Fredric Silberberg 2014-09-24 22:29:00 -04:00
parent 50c84a2f7d
commit 64600ac668
3 changed files with 9 additions and 8 deletions

2
cat.go
View File

@ -2,5 +2,5 @@ package jsh
type CatOutput struct { type CatOutput struct {
Output string Output string
Files []string Files []string
} }

View File

@ -3,26 +3,28 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"jsh"
"io/ioutil" "io/ioutil"
"jsh"
) )
func catFiles(queue chan *jsh.JshFrame) { func catFiles(queue chan *jsh.JshFrame) {
// Get all of the non-flags. The rest were processed by the main function // Get all of the non-flags. The rest were processed by the main function
fileNames := flag.Args() fileNames := flag.Args()
for _,fileName := range fileNames { for _, fileName := range fileNames {
file, err := ioutil.ReadFile(fileName) file, err := ioutil.ReadFile(fileName)
var jshFrame jsh.JshFrame var jshFrame jsh.JshFrame
// If there's an error, output an error frame to the queue and continue
if err != nil { if err != nil {
errText := make(map[string]string) errText := make(map[string]string)
errText[fileName] = fmt.Sprintf("%s",err.Error()) errText[fileName] = fmt.Sprintf("%s", err.Error())
jshFrame = jsh.JshFrame{"", errText} jshFrame = jsh.JshFrame{"", errText}
queue <- &jshFrame queue <- &jshFrame
continue continue
} }
// Put the file contents into a frame and send them to the output
output := jsh.CatOutput{} output := jsh.CatOutput{}
output.Files = []string{fileName} output.Files = []string{fileName}
output.Output = string(file) output.Output = string(file)
@ -51,4 +53,3 @@ func main() {
runJsonMode() runJsonMode()
} }
} }

View File

@ -2,8 +2,8 @@ package main
import ( import (
"jsh" "jsh"
"testing"
"reflect" "reflect"
"testing"
) )
func testUnitError(expected jsh.Unit, t *testing.T) { func testUnitError(expected jsh.Unit, t *testing.T) {
@ -45,14 +45,14 @@ func TestConvertBadUnit(t *testing.T) {
func TestParseGoodLine(t *testing.T) { func TestParseGoodLine(t *testing.T) {
goodLine := "MemTotal: 16370344 kB" goodLine := "MemTotal: 16370344 kB"
expectedStat := jsh.MemStat { 16370344, jsh.KB } expectedStat := jsh.MemStat{16370344, jsh.KB}
expectedKey := "MemTotal" expectedKey := "MemTotal"
key, stat, err := ParseLine(goodLine) key, stat, err := ParseLine(goodLine)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
if key != expectedKey { if key != expectedKey {
t.Errorf("Expected key %s, got key %s", expectedKey, key) t.Errorf("Expected key %s, got key %s", expectedKey, key)
} }
if !reflect.DeepEqual(expectedStat, stat) { if !reflect.DeepEqual(expectedStat, stat) {
t.Error("Expected stat ", expectedStat, " got ", stat) t.Error("Expected stat ", expectedStat, " got ", stat)