diff --git a/cat.go b/cat.go index 2d14bf1..6e5b0f7 100644 --- a/cat.go +++ b/cat.go @@ -2,5 +2,5 @@ package jsh type CatOutput struct { Output string - Files []string + Files []string } diff --git a/cat/main.go b/cat/main.go index 6959ea6..5cb2ff0 100644 --- a/cat/main.go +++ b/cat/main.go @@ -3,26 +3,28 @@ package main import ( "flag" "fmt" - "jsh" "io/ioutil" + "jsh" ) func catFiles(queue chan *jsh.JshFrame) { // Get all of the non-flags. The rest were processed by the main function fileNames := flag.Args() - for _,fileName := range fileNames { + for _, fileName := range fileNames { file, err := ioutil.ReadFile(fileName) var jshFrame jsh.JshFrame + // If there's an error, output an error frame to the queue and continue if err != nil { errText := make(map[string]string) - errText[fileName] = fmt.Sprintf("%s",err.Error()) + errText[fileName] = fmt.Sprintf("%s", err.Error()) jshFrame = jsh.JshFrame{"", errText} queue <- &jshFrame continue } + // Put the file contents into a frame and send them to the output output := jsh.CatOutput{} output.Files = []string{fileName} output.Output = string(file) @@ -51,4 +53,3 @@ func main() { runJsonMode() } } - diff --git a/free/main_test.go b/free/main_test.go index c60e170..c09603e 100644 --- a/free/main_test.go +++ b/free/main_test.go @@ -2,8 +2,8 @@ package main import ( "jsh" - "testing" "reflect" + "testing" ) func testUnitError(expected jsh.Unit, t *testing.T) { @@ -45,14 +45,14 @@ func TestConvertBadUnit(t *testing.T) { func TestParseGoodLine(t *testing.T) { goodLine := "MemTotal: 16370344 kB" - expectedStat := jsh.MemStat { 16370344, jsh.KB } + expectedStat := jsh.MemStat{16370344, jsh.KB} expectedKey := "MemTotal" key, stat, err := ParseLine(goodLine) if err != nil { t.Error(err) } 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) { t.Error("Expected stat ", expectedStat, " got ", stat)