Skip to content

Commit 85776fd

Browse files
adding io.Writer
1 parent 781c982 commit 85776fd

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

flags/abilityflagset.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/digitalghost-dev/poke-cli/styling"
88
"golang.org/x/text/cases"
99
"golang.org/x/text/language"
10+
"io"
1011
"strings"
1112
)
1213

@@ -27,12 +28,14 @@ func SetupAbilityFlagSet() (*flag.FlagSet, *bool, *bool) {
2728
return abilityFlags, pokemonFlag, shortPokemonFlag
2829
}
2930

30-
func PokemonAbilitiesFlag(endpoint string, abilityName string) error {
31+
func PokemonAbilitiesFlag(w io.Writer, endpoint string, abilityName string) error {
3132
abilitiesStruct, _, _ := connections.AbilityApiCall(endpoint, abilityName, connections.APIURL)
3233

3334
capitalizedEffect := cases.Title(language.English).String(strings.ReplaceAll(abilityName, "-", " "))
3435

35-
fmt.Printf("\n%s\n\n", styling.StyleUnderline.Render("Pokemon with", capitalizedEffect))
36+
if _, err := fmt.Fprintf(w, "\n%s\n\n", styling.StyleUnderline.Render("Pokemon with "+capitalizedEffect)); err != nil {
37+
return err
38+
}
3639

3740
// Extract Pokémon names and capitalize them
3841
var pokemonNames []string
@@ -42,15 +45,16 @@ func PokemonAbilitiesFlag(endpoint string, abilityName string) error {
4245

4346
// Print names in a grid format
4447
const cols = 3
45-
4648
for i, name := range pokemonNames {
47-
entry := fmt.Sprintf("%2d. %-30s", i+1, name) // Numbered entry with padding
48-
fmt.Print(entry)
49+
entry := fmt.Sprintf("%2d. %-30s", i+1, name)
50+
fmt.Fprint(w, entry)
4951
if (i+1)%cols == 0 {
50-
fmt.Println()
52+
fmt.Fprintln(w)
5153
}
5254
}
53-
fmt.Println()
55+
if _, err := fmt.Fprintln(w); err != nil {
56+
return err
57+
}
5458

5559
return nil
5660
}

0 commit comments

Comments
 (0)