-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
92 lines (73 loc) · 2.09 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright (c) 2024 Vasiliy Vasilyuk. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"flag"
"fmt"
"math/rand/v2"
"os"
)
// Define the set of Hiragana syllables in Romaji.
var hiraganaSyllables = []string{
// "a", "i", "u", "e", "o",
"ka", "ki", "ku", "ke", "ko",
"sa" /*"shi",*/, "su", "se", "so",
"ta" /*"chi", "tsu",*/, "te", "to",
"na", "ni", "nu", "ne", "no",
"ha", "hi", "fu", "he", "ho",
"ma", "mi", "mu", "me", "mo",
"ya", "yu", "yo",
"ra", "ri", "ru", "re", "ro",
"wa", "wo",
// "n",
}
// Function to generate a random string of Hiragana syllables.
func generateHiraganaString(syllableCount int) string {
result := ""
for i := 0; i < syllableCount; i++ {
randomIndex := rand.IntN(len(hiraganaSyllables))
result += hiraganaSyllables[randomIndex]
}
return result
}
// Function to display help information.
func displayHelp() {
fmt.Println("Usage: nunino [options]")
fmt.Println("Options:")
fmt.Println(" -lines, -l int")
fmt.Println(" Number of lines to output (default 1)")
fmt.Println(" -syllables, -s int")
fmt.Println(" Number of syllables per line (default 3)")
}
// Function to display error messages.
func displayError(message string) {
fmt.Fprintln(os.Stderr, message)
}
func main() {
fs := flag.NewFlagSet("nunino", flag.ContinueOnError)
lines := fs.Int("lines", 1, "Number of lines to output")
syllables := fs.Int("syllables", 3, "Number of syllables per line")
// Add shorthand flags.
fs.IntVar(lines, "l", 1, "Number of lines to output")
fs.IntVar(syllables, "s", 3, "Number of syllables per line")
fs.Usage = displayHelp
if err := fs.Parse(os.Args[1:]); err != nil {
displayHelp()
return
}
if *lines < 1 {
displayError("Error: The number of lines must be at least 1.")
displayHelp()
return
}
if *syllables < 1 {
displayError("Error: The number of syllables must be at least 1.")
displayHelp()
return
}
for i := 0; i < *lines; i++ {
hiraganaString := generateHiraganaString(*syllables)
fmt.Println(hiraganaString)
}
}