-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (50 loc) · 1.36 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"embed"
"fmt"
"log"
"math/rand"
"os"
"strconv"
"strings"
"time"
)
//go:embed harry
var embedHarryFiles embed.FS
func getNumberOfHarryFiles() int {
files, err := embedHarryFiles.ReadDir("harry")
if err != nil {
log.Fatal(err)
}
return len(files)
}
func main() {
if len(os.Args) == 1 || (len(os.Args) == 2 && os.Args[1] == "-h") || (len(os.Args) == 2 && os.Args[1] == "--help") {
fmt.Printf("Harrysay is inspired by Cowsay.\nHarrysay displays a message by young Harry Potter.\n\nUsage:\n harrysay MESSAGE\n\nExample:\n harrysay Hello Prof Snape!\n")
return
}
if len(os.Args) > 1 {
message := strings.Join(os.Args[1:], " ")
totalCharactersInMessage := len(message)
verticalBorderLine := " "
for i := 0; i < totalCharactersInMessage; i++ {
verticalBorderLine += "-"
}
verticalBorderLine += " "
fmt.Println(verticalBorderLine)
fmt.Printf("\n<%s>\n", message)
fmt.Println(verticalBorderLine)
fmt.Println(" \\")
fmt.Println(" \\")
fmt.Println(" \\")
fmt.Println(" \\")
fmt.Println(" \\")
rand.Seed(time.Now().UnixNano())
fileNumber := rand.Intn(getNumberOfHarryFiles() - 1)
file, err := embedHarryFiles.ReadFile("harry/harry_" + strconv.Itoa(fileNumber+1) + ".txt")
if err != nil {
log.Fatal("Error reading the ASCII file!")
}
fmt.Println(string(file))
}
}