diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5625311 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/phonetic-letters diff --git a/README.asciidoc b/README.asciidoc new file mode 100644 index 0000000..f39ab27 --- /dev/null +++ b/README.asciidoc @@ -0,0 +1,80 @@ += phonetic-letters + +This is a simple application which reveals the code word(s) from the NATO phonetic alphabet for a given set of letters from the English alphabet. + +This app can be used to help you memorize the NATO phonetic alphabet. + +== Installation + +=== Requirements + +==== Go + +A minimum version of Go 1.21.0 is required for installing spruce. +Please go https://go.dev/dl/[here] to download the latest version. + +=== Install with Go + +[source,console] +---- +git clone https://codeflow.dananglin.me.uk/apollo/phonetic-letters.git +cd phonetic-letters +go install . +---- + +== Usage + +Reveal the code word for `g`: +[source,console] +---- +$ phonetic-letters g +G - Golf +---- + +Reveal the code words for all the letters in `Hello, World!`: +[source,console] +---- +$ phonetic-letters Hello, World! +H - Hotel +E - Echo +L - Lima +L - Lima +O - Oscar +W - Whiskey +O - Oscar +R - Romeo +L - Lima +D - Delta +---- + +Reveal the code words for all letters of the alphabet: +[source,console] +---- +$ ./phonetic-letters --all +A - Alpha +B - Bravo +C - Charlie +D - Delta +E - Echo +F - Foxtrot +G - Golf +H - Hotel +I - India +J - Juliet +K - Kilo +L - Lima +M - Mike +N - November +O - Oscar +P - Papa +Q - Quebec +R - Romeo +S - Sierra +T - Tango +U - Uniform +V - Victor +W - Whiskey +X - Xray +Y - Yankee +Z - Zulu +---- diff --git a/README.md b/README.md deleted file mode 100644 index 37f4f8d..0000000 --- a/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# phonetic-letters - -Reveals the code words from the NATO phonetic alphabet for a given set of letters from the alphabet. \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..a0463ed --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module codeflow.dananglin.me.uk/apollo/phonetic-letters + +go 1.21 diff --git a/phonetic_letters.go b/phonetic_letters.go new file mode 100644 index 0000000..d5d3cd3 --- /dev/null +++ b/phonetic_letters.go @@ -0,0 +1,104 @@ +package main + +import ( + "flag" + "fmt" + "os" + "strings" +) + +func main() { + var all bool + + flag.BoolVar(&all, "all", false, "reveal the code words of all the letters in the English alphabet.") + flag.Parse() + + if all { + fmt.Println(phoneticLetters(fullAlphabet())) + return + } + + args := flag.Args() + + if len(args) < 1 { + fmt.Println("ERROR: expected an argument") + os.Exit(1) + } else if len(args) == 1 { + fmt.Println(phoneticLetters(args[0])) + } else { + input := "" + for i := range args { + input = input + args[i] + } + fmt.Println(phoneticLetters(input)) + } +} + +func phoneticLetters(letters string) string { + letters = strings.ToLower(letters) + + b := strings.Builder{} + + for _, r := range letters { + switch r { + case 'a': + b.WriteString("A - Alpha\n") + case 'b': + b.WriteString("B - Bravo\n") + case 'c': + b.WriteString("C - Charlie\n") + case 'd': + b.WriteString("D - Delta\n") + case 'e': + b.WriteString("E - Echo\n") + case 'f': + b.WriteString("F - Foxtrot\n") + case 'g': + b.WriteString("G - Golf\n") + case 'h': + b.WriteString("H - Hotel\n") + case 'i': + b.WriteString("I - India\n") + case 'j': + b.WriteString("J - Juliet\n") + case 'k': + b.WriteString("K - Kilo\n") + case 'l': + b.WriteString("L - Lima\n") + case 'm': + b.WriteString("M - Mike\n") + case 'n': + b.WriteString("N - November\n") + case 'o': + b.WriteString("O - Oscar\n") + case 'p': + b.WriteString("P - Papa\n") + case 'q': + b.WriteString("Q - Quebec\n") + case 'r': + b.WriteString("R - Romeo\n") + case 's': + b.WriteString("S - Sierra\n") + case 't': + b.WriteString("T - Tango\n") + case 'u': + b.WriteString("U - Uniform\n") + case 'v': + b.WriteString("V - Victor\n") + case 'w': + b.WriteString("W - Whiskey\n") + case 'x': + b.WriteString("X - Xray\n") + case 'y': + b.WriteString("Y - Yankee\n") + case 'z': + b.WriteString("Z - Zulu\n") + } + } + + return b.String() +} + +func fullAlphabet() string { + return "a b c d e f g h i j k l m n o p q r s t u v w x y z" +}