Skip to content

Commit 87a4b82

Browse files
committed
chore: fix deprecation warning
1 parent 22c1e74 commit 87a4b82

File tree

5 files changed

+31
-14
lines changed

5 files changed

+31
-14
lines changed

cmd/flags.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package cmd
22

3-
import (
4-
"flag"
5-
)
3+
import "flag"
4+
65

76
func resolveFlag[T comparable](longVal, shortVal *T, zero T, longName, shortName string) T {
87
if *longVal != zero && *shortVal != zero {
98
repeatedFlag(longName, shortName)
109
}
10+
1111
if *longVal != zero {
1212
return *longVal
1313
}
14+
1415
return *shortVal
1516
}
1617

cmd/root.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import (
55
"os"
66

77
chigo "github.com/UltiRequiem/chigo/pkg"
8-
"github.com/UltiRequiem/lorelai/pkg"
8+
lorelai "github.com/UltiRequiem/lorelai/pkg"
99
)
1010

11-
const VERSION = "1.0.0"
11+
const VERSION = "1.1.1"
1212

1313
func Main() {
14-
help, words, paragraphs, sentences, output, url, email, colors := flags()
14+
help, words, paragraphs, sentences, fileToWrite, url, email, colors := flags()
1515

1616
if help {
1717
printHelp()
@@ -45,17 +45,18 @@ func Main() {
4545
text += "\n\n"
4646
}
4747

48-
if output != "" {
49-
err := os.WriteFile(output, []byte(text), 0664)
48+
if fileToWrite != "" {
49+
err := os.WriteFile(fileToWrite, []byte(text), 0664)
50+
5051
if err != nil {
51-
error(fmt.Sprintf("Error while trying to write %s.", output))
52+
error(fmt.Sprintf("Error while trying to write %s.", fileToWrite))
5253
}
5354

5455
return
5556
}
5657

5758
if text != "" {
58-
textNoNewline := text[0 : len(text)-1]
59+
textNoNewline := text[0 : len(text)-2] // Remove the new line at the end
5960

6061
if colors {
6162
chigo.PrintWithColors(textNoNewline)

pkg/root.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import (
77
"time"
88
)
99

10+
var rng = rand.New(rand.NewSource(time.Now().UnixNano()))
11+
1012
// Get [quantity] words
1113
func LoremWords(quantity int) string {
12-
rand.Seed(time.Now().UnixNano())
1314

1415
lorem := ""
1516

1617
for i := 0; i < quantity; i++ {
17-
lorem += DATA[rand.Intn(1100)] + " "
18+
lorem += DATA[rng.Intn(1100)] + " "
1819
}
1920

2021
return lorem
@@ -29,7 +30,12 @@ func FormattedLoremWords(quantity int) string {
2930
// Get a single word
3031
func Word() string {
3132
word := LoremWords(1)
32-
return strings.TrimSpace(strings.ToUpper(word[0:1]) + word[1:])
33+
34+
return strings.TrimSpace(strings.ToTitle(word))
35+
}
36+
37+
func Tittle() string {
38+
return strings.ToTitle(LoremWords(1))
3339
}
3440

3541
// Get a sentence, with the first word capitalized, of eight words that ends with a dot.

pkg/root_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ func TestFormattedLoremWords(t *testing.T) {
3232
func TestWord(t *testing.T) {
3333
result := Word()
3434
words := strings.Fields(result)
35+
3536
if len(words) != 1 {
3637
t.Errorf("Expected a single word, got %d words", len(words))
3738
}
39+
3840
if result[0] < 'A' || result[0] > 'Z' {
3941
t.Errorf("Expected word to start with an uppercase letter, got %c", result[0])
4042
}

pkg/utils.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@ package lorelai
22

33
import "strings"
44

5+
func capitalizeFirstWord(text string) string {
6+
if len(text) == 0 {
7+
return text
8+
}
9+
return strings.ToUpper(text[:1]) + text[1:]
10+
}
11+
512
// Trim spaces and adds a dot at the end.
613
func formatWords(textToFormat string) string {
7-
return trimSpaceAddDot(strings.ToUpper(textToFormat[0:1]) + textToFormat[1:])
14+
return trimSpaceAddDot(capitalizeFirstWord(textToFormat))
815
}
916

1017
func trimSpaceAddDot(text string) string {

0 commit comments

Comments
 (0)