Skip to content

Commit a519245

Browse files
Merge pull request #141 from digitalghost-dev/1.2.3
1.2.3
2 parents dfe84f5 + 4c18856 commit a519245

34 files changed

+411
-449
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ on:
2626
- main
2727

2828
env:
29-
VERSION_NUMBER: 'v1.2.2'
29+
VERSION_NUMBER: 'v1.2.3'
3030
DOCKERHUB_REGISTRY_NAME: 'digitalghostdev/poke-cli'
3131
AWS_REGION: 'us-west-2'
3232

.goreleaser.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ builds:
1414
- windows
1515
- darwin
1616
ldflags:
17-
- -s -w -X main.version=v1.2.2
17+
- -s -w -X main.version=v1.2.3
1818

1919
archives:
2020
- format: tar.gz

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# build 1
2-
FROM golang:1.24.1-alpine3.21 AS build
2+
FROM golang:1.24.2-alpine3.21 AS build
33

44
WORKDIR /app
55

@@ -8,7 +8,7 @@ RUN go mod download
88

99
COPY . .
1010

11-
RUN go build -ldflags "-X main.version=v1.2.2" -o poke-cli .
11+
RUN go build -ldflags "-X main.version=v1.2.3" -o poke-cli .
1212

1313
# build 2
1414
FROM --platform=$BUILDPLATFORM alpine:latest

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<img height="250" width="350" src="pokemon.svg" alt="pokemon-logo"/>
33
<h1>Pokémon CLI</h1>
44
<img src="https://img.shields.io/github/v/release/digitalghost-dev/poke-cli?style=flat-square&logo=git&logoColor=FFCC00&label=Release%20Version&labelColor=EEE&color=FFCC00" alt="version-label">
5-
<img src="https://img.shields.io/docker/image-size/digitalghostdev/poke-cli/v1.2.2?arch=arm64&style=flat-square&logo=docker&logoColor=FFCC00&labelColor=EEE&color=FFCC00" alt="docker-image-size">
5+
<img src="https://img.shields.io/docker/image-size/digitalghostdev/poke-cli/v1.2.3?arch=arm64&style=flat-square&logo=docker&logoColor=FFCC00&labelColor=EEE&color=FFCC00" alt="docker-image-size">
66
<img src="https://img.shields.io/github/actions/workflow/status/digitalghost-dev/poke-cli/ci.yml?branch=main&style=flat-square&logo=github&logoColor=FFCC00&label=CI&labelColor=EEE&color=FFCC00" alt="ci-status-badge">
77
</div>
88
<div align="center">
@@ -76,11 +76,11 @@ View future plans in the [Roadmap](#roadmap) section.
7676
3. Choose how to interact with the container:
7777
* Run a single command and exit:
7878
```bash
79-
docker run --rm -it digitalghostdev/poke-cli:v1.2.2 <command> [subcommand] flag]
79+
docker run --rm -it digitalghostdev/poke-cli:v1.2.3 <command> [subcommand] flag]
8080
```
8181
* Enter the container and use its shell:
8282
```bash
83-
docker run --rm -it --name poke-cli --entrypoint /bin/sh digitalghostdev/poke-cli:v1.2.2 -c "cd /app && exec sh"
83+
docker run --rm -it --name poke-cli --entrypoint /bin/sh digitalghostdev/poke-cli:v1.2.3 -c "cd /app && exec sh"
8484
# placed into the /app directory, run the program with './poke-cli'
8585
# example: ./poke-cli ability swift-swim
8686
```

cli.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import (
44
"flag"
55
"fmt"
66
"github.com/digitalghost-dev/poke-cli/cmd"
7+
"github.com/digitalghost-dev/poke-cli/cmd/ability"
78
"github.com/digitalghost-dev/poke-cli/cmd/move"
9+
"github.com/digitalghost-dev/poke-cli/cmd/natures"
810
"github.com/digitalghost-dev/poke-cli/cmd/search"
911
"github.com/digitalghost-dev/poke-cli/cmd/types"
1012
"github.com/digitalghost-dev/poke-cli/flags"
@@ -22,7 +24,7 @@ func currentVersion() {
2224
return
2325
}
2426

25-
// Fallback to build info when version is not set
27+
// Fallback to build info when the version is not set
2628
buildInfo, ok := debug.ReadBuildInfo()
2729
if !ok {
2830
fmt.Println("Version: unknown (unable to read build info)")
@@ -36,6 +38,12 @@ func currentVersion() {
3638
}
3739
}
3840

41+
func printWrapper(f func() string) func() {
42+
return func() {
43+
fmt.Println(f())
44+
}
45+
}
46+
3947
func runCLI(args []string) int {
4048
mainFlagSet := flag.NewFlagSet("poke-cli", flag.ContinueOnError)
4149

@@ -89,11 +97,11 @@ func runCLI(args []string) int {
8997
}
9098

9199
commands := map[string]func(){
92-
"ability": cmd.AbilityCommand,
93-
"move": move.MoveCommand,
94-
"natures": cmd.NaturesCommand,
100+
"ability": printWrapper(ability.AbilityCommand),
101+
"move": printWrapper(move.MoveCommand),
102+
"natures": printWrapper(natures.NaturesCommand),
95103
"pokemon": cmd.PokemonCommand,
96-
"types": types.TypesCommand,
104+
"types": printWrapper(types.TypesCommand),
97105
"search": search.SearchCommand,
98106
}
99107

cmd/ability.go renamed to cmd/ability/ability.go

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
package cmd
1+
package ability
22

33
import (
44
"flag"
55
"fmt"
6+
"github.com/digitalghost-dev/poke-cli/cmd/utils"
67
"github.com/digitalghost-dev/poke-cli/connections"
78
"github.com/digitalghost-dev/poke-cli/flags"
89
"github.com/digitalghost-dev/poke-cli/styling"
@@ -12,7 +13,9 @@ import (
1213
"strings"
1314
)
1415

15-
func AbilityCommand() {
16+
func AbilityCommand() string {
17+
var output strings.Builder
18+
1619
flag.Usage = func() {
1720
helpMessage := styling.HelpBorder.Render(
1821
"Get details about a specific ability.\n\n",
@@ -24,7 +27,7 @@ func AbilityCommand() {
2427
fmt.Sprintf("\n\t%-30s %s", "-p, --pokemon", "Prints Pokémon that learn this ability."),
2528
fmt.Sprintf("\n\t%-30s %s", "-h, --help", "Prints the help menu."),
2629
)
27-
fmt.Println(helpMessage)
30+
output.WriteString(helpMessage)
2831
}
2932

3033
abilityFlags, pokemonFlag, shortPokemonFlag := flags.SetupAbilityFlagSet()
@@ -35,33 +38,33 @@ func AbilityCommand() {
3538

3639
if len(os.Args) == 3 && (os.Args[2] == "-h" || os.Args[2] == "--help") {
3740
flag.Usage()
38-
return
41+
return output.String()
3942
}
4043

41-
if err := ValidateAbilityArgs(args); err != nil {
42-
fmt.Println(err.Error())
43-
if os.Getenv("GO_TESTING") != "1" {
44-
os.Exit(1)
45-
}
44+
if err := utils.ValidateAbilityArgs(args); err != nil {
45+
output.WriteString(err.Error())
46+
return output.String()
4647
}
4748

4849
endpoint := strings.ToLower(args[1])
4950
abilityName := strings.ToLower(args[2])
5051

5152
if err := abilityFlags.Parse(args[3:]); err != nil {
52-
fmt.Printf("error parsing flags: %v\n", err)
53+
output.WriteString(fmt.Sprintf("error parsing flags: %v\n", err))
5354
abilityFlags.Usage()
5455
if os.Getenv("GO_TESTING") != "1" {
5556
os.Exit(1)
5657
}
58+
return output.String()
5759
}
5860

5961
abilitiesStruct, abilityName, err := connections.AbilityApiCall(endpoint, abilityName, connections.APIURL)
6062
if err != nil {
61-
fmt.Println(err)
6263
if os.Getenv("GO_TESTING") != "1" {
64+
fmt.Fprintln(os.Stderr, err)
6365
os.Exit(1)
6466
}
67+
return err.Error()
6568
}
6669

6770
// Extract English short_effect
@@ -83,29 +86,33 @@ func AbilityCommand() {
8386
}
8487

8588
capitalizedAbility := cases.Title(language.English).String(strings.ReplaceAll(abilityName, "-", " "))
86-
fmt.Println(styling.StyleBold.Render(capitalizedAbility))
89+
output.WriteString(styling.StyleBold.Render(capitalizedAbility) + "\n")
8790

8891
// API is missing some data for the short_effect for abilities from Generation 9.
8992
// If short_effect is empty, fallback to the move's flavor_text_entry.
9093
if englishShortEffect == "" {
91-
fmt.Println("Effect:", englishFlavorEntry)
94+
output.WriteString("Effect: " + englishFlavorEntry + "\n")
9295
} else {
93-
fmt.Println("Effect:", englishShortEffect)
96+
output.WriteString("Effect: " + englishShortEffect + "\n")
9497
}
9598

9699
// Print the generation where the move was first introduced.
97100
generationParts := strings.Split(abilitiesStruct.Generation.Name, "-")
98101
if len(generationParts) > 1 {
99102
generationUpper := strings.ToUpper(generationParts[1])
100-
fmt.Println("Generation:", generationUpper)
103+
output.WriteString("Generation: " + generationUpper + "\n")
101104
} else {
102-
fmt.Println("Generation: Unknown")
105+
output.WriteString("Generation: Unknown\n")
103106
}
104107

105108
if *pokemonFlag || *shortPokemonFlag {
106-
if err := flags.PokemonAbilitiesFlag(endpoint, abilityName); err != nil {
107-
fmt.Printf("error parsing flags: %v\n", err)
108-
os.Exit(1)
109+
if err := flags.PokemonAbilitiesFlag(&output, endpoint, abilityName); err != nil {
110+
output.WriteString(fmt.Sprintf("error parsing flags: %v\n", err))
111+
if os.Getenv("GO_TESTING") != "1" {
112+
os.Exit(1)
113+
}
109114
}
110115
}
116+
117+
return output.String()
111118
}

cmd/ability/ability_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package ability
2+
3+
import (
4+
"github.com/digitalghost-dev/poke-cli/cmd/utils"
5+
"github.com/digitalghost-dev/poke-cli/styling"
6+
"github.com/stretchr/testify/assert"
7+
"os"
8+
"testing"
9+
)
10+
11+
func TestAbilityCommand(t *testing.T) {
12+
err := os.Setenv("GO_TESTING", "1")
13+
if err != nil {
14+
t.Fatalf("Failed to set GO_TESTING env var: %v", err)
15+
}
16+
17+
defer func() {
18+
err := os.Unsetenv("GO_TESTING")
19+
if err != nil {
20+
t.Logf("Warning: failed to unset GO_TESTING: %v", err)
21+
}
22+
}()
23+
24+
tests := []struct {
25+
name string
26+
args []string
27+
expectedOutput string
28+
wantError bool
29+
}{
30+
{
31+
name: "Ability help flag",
32+
args: []string{"ability", "--help"},
33+
expectedOutput: utils.LoadGolden(t, "ability_help.golden"),
34+
},
35+
{
36+
name: "Ability command: clear-body",
37+
args: []string{"ability", "clear-body"},
38+
expectedOutput: utils.LoadGolden(t, "ability.golden"),
39+
},
40+
{
41+
name: "Misspelled ability name",
42+
args: []string{"ability", "bulletproff"},
43+
expectedOutput: utils.LoadGolden(t, "ability_misspelled.golden"),
44+
wantError: true,
45+
},
46+
}
47+
48+
for _, tt := range tests {
49+
t.Run(tt.name, func(t *testing.T) {
50+
originalArgs := os.Args
51+
os.Args = append([]string{"poke-cli"}, tt.args...)
52+
defer func() { os.Args = originalArgs }()
53+
54+
output := AbilityCommand()
55+
cleanOutput := styling.StripANSI(output)
56+
57+
assert.Equal(t, tt.expectedOutput, cleanOutput, "Output should match expected")
58+
})
59+
}
60+
}

cmd/ability_test.go

Lines changed: 0 additions & 113 deletions
This file was deleted.

0 commit comments

Comments
 (0)