Skip to content

Commit b047c56

Browse files
importing functions from utils package
1 parent e9b3041 commit b047c56

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

cli.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/digitalghost-dev/poke-cli/cmd/pokemon"
1010
"github.com/digitalghost-dev/poke-cli/cmd/search"
1111
"github.com/digitalghost-dev/poke-cli/cmd/types"
12+
"github.com/digitalghost-dev/poke-cli/cmd/utils"
1213
"github.com/digitalghost-dev/poke-cli/flags"
1314
"github.com/digitalghost-dev/poke-cli/styling"
1415
"os"
@@ -39,19 +40,6 @@ func currentVersion() {
3940
}
4041
}
4142

42-
// handleCommandOutput wraps a function that returns (string, error) into a no-arg function
43-
// that prints the output to stdout or stderr depending on whether an error occurred.
44-
func handleCommandOutput(fn func() (string, error)) func() {
45-
return func() {
46-
output, err := fn()
47-
if err != nil {
48-
fmt.Fprintln(os.Stderr, output)
49-
return
50-
}
51-
fmt.Println(output)
52-
}
53-
}
54-
5543
func runCLI(args []string) int {
5644
var output strings.Builder
5745

@@ -107,11 +95,11 @@ func runCLI(args []string) int {
10795
}
10896

10997
commands := map[string]func(){
110-
"ability": handleCommandOutput(ability.AbilityCommand),
111-
"move": handleCommandOutput(move.MoveCommand),
112-
"natures": handleCommandOutput(natures.NaturesCommand),
113-
"pokemon": handleCommandOutput(pokemon.PokemonCommand),
114-
"types": handleCommandOutput(types.TypesCommand),
98+
"ability": utils.HandleCommandOutput(ability.AbilityCommand),
99+
"move": utils.HandleCommandOutput(move.MoveCommand),
100+
"natures": utils.HandleCommandOutput(natures.NaturesCommand),
101+
"pokemon": utils.HandleCommandOutput(pokemon.PokemonCommand),
102+
"types": utils.HandleCommandOutput(types.TypesCommand),
115103
"search": search.SearchCommand,
116104
}
117105

0 commit comments

Comments
 (0)