Skip to content

Commit 361d23a

Browse files
Merge pull request #154 from digitalghost-dev/1.3.2
1.3.2
2 parents ef71de0 + e54611d commit 361d23a

File tree

5 files changed

+61
-25
lines changed

5 files changed

+61
-25
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.3.1'
29+
VERSION_NUMBER: 'v1.3.2'
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.3.1
17+
- -s -w -X main.version=v1.3.2
1818

1919
archives:
2020
- format: tar.gz

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ RUN go mod download
88

99
COPY . .
1010

11-
RUN go build -ldflags "-X main.version=v1.3.1" -o poke-cli .
11+
RUN go build -ldflags "-X main.version=v1.3.2" -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.3.1?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.3.2?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.3.1 <command> [subcommand] flag]
79+
docker run --rm -it digitalghostdev/poke-cli:v1.3.2 <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.3.1 -c "cd /app && exec sh"
83+
docker run --rm -it --name poke-cli --entrypoint /bin/sh digitalghostdev/poke-cli:v1.3.2 -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
```

flags/pokemonflagset.go

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"sort"
2121
"strconv"
2222
"strings"
23+
"sync"
2324
)
2425

2526
func header(header string) string {
@@ -225,37 +226,72 @@ func MovesFlag(w io.Writer, endpoint string, pokemonName string) error {
225226

226227
var moves []MoveInfo
227228

229+
movesChan := make(chan MoveInfo)
230+
errorsChan := make(chan error)
231+
232+
var wg sync.WaitGroup
233+
234+
// Count eligible moves for concurrency
235+
eligibleMoves := 0
228236
for _, pokeMove := range pokemonStruct.Moves {
229237
for _, detail := range pokeMove.VersionGroupDetails {
230238
if detail.VersionGroup.Name != "scarlet-violet" || detail.MoveLearnedMethod.Name != "level-up" {
231239
continue
232240
}
233241

234-
moveName := pokeMove.Move.Name
235-
moveStruct, _, err := connections.MoveApiCall("move", moveName, baseURL)
236-
if err != nil {
237-
log.Printf("Error fetching move %s: %v", moveName, err)
242+
eligibleMoves++
243+
wg.Add(1)
244+
go func(moveName string, level int) {
245+
defer wg.Done()
246+
247+
moveStruct, _, err := connections.MoveApiCall("move", moveName, baseURL)
248+
if err != nil {
249+
errorsChan <- fmt.Errorf("error fetching move %s: %v", moveName, err)
250+
return
251+
}
252+
253+
capitalizedMove := cases.Title(language.English).String(strings.ReplaceAll(moveName, "-", " "))
254+
capitalizedType := cases.Title(language.English).String(moveStruct.Type.Name)
255+
256+
movesChan <- MoveInfo{
257+
Accuracy: moveStruct.Accuracy,
258+
Level: level,
259+
Name: capitalizedMove,
260+
Power: moveStruct.Power,
261+
Type: capitalizedType,
262+
}
263+
}(pokeMove.Move.Name, detail.LevelLearnedAt)
264+
}
265+
}
266+
267+
// Close channels when all goroutines are done
268+
go func() {
269+
wg.Wait()
270+
close(movesChan)
271+
close(errorsChan)
272+
}()
273+
274+
// Collect results from channels
275+
movesOpen, errorsOpen := true, true
276+
for movesOpen || errorsOpen {
277+
select {
278+
case move, ok := <-movesChan:
279+
if !ok {
280+
movesOpen = false
238281
continue
239282
}
240-
241-
capitalizedMove := cases.Title(language.English).String(strings.ReplaceAll(moveName, "-", " "))
242-
capitalizedType := cases.Title(language.English).String(moveStruct.Type.Name)
243-
244-
moves = append(moves, MoveInfo{
245-
Accuracy: moveStruct.Accuracy,
246-
Level: detail.LevelLearnedAt,
247-
Name: capitalizedMove,
248-
Power: moveStruct.Power,
249-
Type: capitalizedType,
250-
})
283+
moves = append(moves, move)
284+
case err, ok := <-errorsChan:
285+
if !ok {
286+
errorsOpen = false
287+
continue
288+
}
289+
log.Println(err)
251290
}
252291
}
253292

254293
if len(moves) == 0 {
255-
_, err := fmt.Fprintln(w, "No level-up moves found for Scarlet & Violet.")
256-
if err != nil {
257-
return err
258-
}
294+
fmt.Fprintln(w, "No level-up moves found for Scarlet & Violet.")
259295
return nil
260296
}
261297

0 commit comments

Comments
 (0)