Skip to content

Commit 52def96

Browse files
changing to strings.Builder() to return string (#137)
1 parent f83a1bc commit 52def96

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func runCLI(args []string) int {
101101
"move": printWrapper(move.MoveCommand),
102102
"natures": printWrapper(natures.NaturesCommand),
103103
"pokemon": cmd.PokemonCommand,
104-
"types": types.TypesCommand,
104+
"types": printWrapper(types.TypesCommand),
105105
"search": search.SearchCommand,
106106
}
107107

cmd/types/types.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import (
1212
"strings"
1313
)
1414

15-
func TypesCommand() {
15+
func TypesCommand() string {
16+
var output strings.Builder
17+
1618
flag.Usage = func() {
1719
helpMessage := styling.HelpBorder.Render(
1820
"Get details about a specific typing.\n\n",
@@ -22,23 +24,25 @@ func TypesCommand() {
2224
styling.StyleBold.Render("FLAGS:"),
2325
fmt.Sprintf("\n\t%-30s %s", "-h, --help", "Prints out the help menu"),
2426
)
25-
fmt.Println(helpMessage)
27+
output.WriteString(helpMessage + "\n")
2628
}
2729

2830
flag.Parse()
2931

3032
if len(os.Args) == 3 && (os.Args[2] == "-h" || os.Args[2] == "--help") {
3133
flag.Usage()
32-
return
34+
return output.String()
3335
}
3436

3537
if err := utils.ValidateTypesArgs(os.Args); err != nil {
36-
fmt.Println(err.Error())
38+
output.WriteString(err.Error())
3739
os.Exit(1)
3840
}
3941

4042
endpoint := strings.ToLower(os.Args[1])[0:4]
4143
tableGeneration(endpoint)
44+
45+
return output.String()
4246
}
4347

4448
type model struct {

0 commit comments

Comments
 (0)