arianagiroux 3 недель назад
Родитель
Сommit
7da89c3fbd
3 измененных файлов с 41 добавлено и 0 удалено
  1. 3 0
      cmd/issues.go
  2. 25 0
      io.go
  3. 13 0
      io_test.go

+ 3 - 0
cmd/issues.go

@@ -43,5 +43,8 @@ func main() {
 			fmt.Println("could not run program:", err)
 			os.Exit(1)
 		}
+	} else if issues.IsIssueCollection(arg[0]) {
+		fmt.Println("Collection of Issues:", arg)
+		os.Exit(0)
 	}
 }

+ 25 - 0
io.go

@@ -39,6 +39,31 @@ func IsIssue(path string) bool {
 	return false
 }
 
+// Reports true when the specified path is a directory of Issues
+func IsIssueCollection(path string) bool {
+	if IsIssue(path) {
+		return false
+	}
+
+	files, err := os.ReadDir(path)
+	if err != nil {
+		return false
+	}
+
+	var isIssue []bool
+	for _, file := range files {
+		if IsIssue(path + "/" + file.Name()) {
+			isIssue = append(isIssue, true)
+		}
+	}
+
+	if len(isIssue) > 0 {
+		return true
+	}
+
+	return false
+}
+
 // Writes a issue to disk
 func WriteIssue(issue Issue) (success bool, err error) { return false, nil } // TODO: implement
 

+ 13 - 0
io_test.go

@@ -37,4 +37,17 @@ func Test_IsIssue_returns_false_on_error(t *testing.T) {
 	assert.False(t, val)
 }
 
+func Test_IsIssueCollection_success(t *testing.T) {
+	val := IsIssueCollection("tests/bugs/")
+	assert.True(t, val)
+}
+
+func Test_IsIssueCollection_fail(t *testing.T) {
+	val := IsIssueCollection("tests/")
+	assert.False(t, val)
+}
+
+func Test_IsIssueCollection_returns_false_on_error(t *testing.T) {
+	val := IsIssueCollection("willneverexist")
+	assert.False(t, val)
 }