Skip to content

Commit

Permalink
feat: add output to user when no file or flag has been passed
Browse files Browse the repository at this point in the history
  • Loading branch information
logan-bobo committed Feb 13, 2024
1 parent 03e187b commit 648180b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func countChars(bytes []byte) int {
charCount++
}

// New line counts as one cah so add it here
// New line counts so add it
charCount++
}

Expand Down Expand Up @@ -127,8 +127,14 @@ func main() {
} else {
if len(os.Args) < 3 {
for _, legalFlag := range legalFlags {
if len(os.Args) < 2 {
fmt.Println("No File provided")
os.Exit(1)
}

if os.Args[1] == legalFlag {
panic("Flag set with no filename")
fmt.Println("Flag set with no filename")
os.Exit(1)
}
}
fileName = os.Args[1]
Expand Down
4 changes: 2 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ func TestCharCount(t *testing.T) {
charCountExpected := 339292

if charCount != charCountExpected {
t.Errorf("countWords(%s), FAILED. Expected %d got %d \n", testFile, charCountExpected, charCount)
t.Errorf("countChars(%s), FAILED. Expected %d got %d \n", testFile, charCountExpected, charCount)
} else {
t.Logf("countWords(%s), PASSED.\n", testFile)
t.Logf("countChars(%s), PASSED.\n", testFile)
}
}

0 comments on commit 648180b

Please sign in to comment.