Fredric Silberberg 5 years ago
parent
commit
64600ac668
3 changed files with 9 additions and 8 deletions
  1. 1
    1
      cat.go
  2. 5
    4
      cat/main.go
  3. 3
    3
      free/main_test.go

+ 1
- 1
cat.go View File

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

+ 5
- 4
cat/main.go View File

@@ -3,26 +3,28 @@ package main
3 3
 import (
4 4
 	"flag"
5 5
 	"fmt"
6
-	"jsh"
7 6
 	"io/ioutil"
7
+	"jsh"
8 8
 )
9 9
 
10 10
 func catFiles(queue chan *jsh.JshFrame) {
11 11
 	// Get all of the non-flags. The rest were processed by the main function
12 12
 	fileNames := flag.Args()
13
-	for _,fileName := range fileNames {
13
+	for _, fileName := range fileNames {
14 14
 		file, err := ioutil.ReadFile(fileName)
15 15
 
16 16
 		var jshFrame jsh.JshFrame
17 17
 
18
+		// If there's an error, output an error frame to the queue and continue
18 19
 		if err != nil {
19 20
 			errText := make(map[string]string)
20
-			errText[fileName] = fmt.Sprintf("%s",err.Error())
21
+			errText[fileName] = fmt.Sprintf("%s", err.Error())
21 22
 			jshFrame = jsh.JshFrame{"", errText}
22 23
 			queue <- &jshFrame
23 24
 			continue
24 25
 		}
25 26
 
27
+		// Put the file contents into a frame and send them to the output
26 28
 		output := jsh.CatOutput{}
27 29
 		output.Files = []string{fileName}
28 30
 		output.Output = string(file)
@@ -51,4 +53,3 @@ func main() {
51 53
 		runJsonMode()
52 54
 	}
53 55
 }
54
-

+ 3
- 3
free/main_test.go View File

@@ -2,8 +2,8 @@ package main
2 2
 
3 3
 import (
4 4
 	"jsh"
5
-	"testing"
6 5
 	"reflect"
6
+	"testing"
7 7
 )
8 8
 
9 9
 func testUnitError(expected jsh.Unit, t *testing.T) {
@@ -45,14 +45,14 @@ func TestConvertBadUnit(t *testing.T) {
45 45
 
46 46
 func TestParseGoodLine(t *testing.T) {
47 47
 	goodLine := "MemTotal:       16370344 kB"
48
-	expectedStat := jsh.MemStat { 16370344, jsh.KB }
48
+	expectedStat := jsh.MemStat{16370344, jsh.KB}
49 49
 	expectedKey := "MemTotal"
50 50
 	key, stat, err := ParseLine(goodLine)
51 51
 	if err != nil {
52 52
 		t.Error(err)
53 53
 	}
54 54
 	if key != expectedKey {
55
-		t.Errorf("Expected key %s, got key %s", expectedKey, key) 
55
+		t.Errorf("Expected key %s, got key %s", expectedKey, key)
56 56
 	}
57 57
 	if !reflect.DeepEqual(expectedStat, stat) {
58 58
 		t.Error("Expected stat ", expectedStat, " got ", stat)

Loading…
Cancel
Save