Skip to content

Commit 46d0e4c

Browse files
Merge pull request #165 from digitalghost-dev/1.4.0
1.4.0
2 parents 536810e + 937c522 commit 46d0e4c

32 files changed

+641
-102
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ on:
2828
- main
2929

3030
env:
31-
VERSION_NUMBER: 'v1.3.3'
31+
VERSION_NUMBER: 'v1.4.0'
3232
DOCKERHUB_REGISTRY_NAME: 'digitalghostdev/poke-cli'
3333
AWS_REGION: 'us-west-2'
3434

.goreleaser.yaml renamed to .goreleaser.yml

Lines changed: 3 additions & 3 deletions
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.3
17+
- -s -w -X main.version=v1.4.0
1818

1919
archives:
2020
- formats: [ 'zip' ]
@@ -28,7 +28,7 @@ archives:
2828
# use zip for windows archives
2929
format_overrides:
3030
- goos: windows
31-
- formats: [ 'zip' ]
31+
formats: [ 'zip' ]
3232

3333
changelog:
3434
sort: asc
@@ -51,6 +51,6 @@ homebrew_casks:
5151
hooks:
5252
post:
5353
install: |
54-
if system_command("/usr/bin/xattr", args: ["-h"]).exit_status == 0
54+
if OS.mac? && system_command("/usr/bin/xattr", args: ["-h"]).exit_status == 0
5555
system_command "/usr/bin/xattr", args: ["-dr", "com.apple.quarantine", "#{staged_path}/poke-cli"]
5656
end

Dockerfile

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

44
WORKDIR /app
55

@@ -8,13 +8,14 @@ RUN go mod download
88

99
COPY . .
1010

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

1313
# build 2
14-
FROM --platform=$BUILDPLATFORM alpine:latest
14+
FROM --platform=$BUILDPLATFORM alpine:3.22
1515

1616
# Install only necessary packages and remove them after use
17-
RUN apk add --no-cache shadow && \
17+
RUN apk upgrade && \
18+
apk add --no-cache shadow && \
1819
addgroup -S poke_group && adduser -S poke_user -G poke_group && \
1920
sed -i 's/^root:.*/root:!*:0:0:root:\/root:\/sbin\/nologin/' /etc/passwd && \
2021
apk del shadow

README.md

Lines changed: 26 additions & 15 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.3?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.4.0?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">
@@ -77,22 +77,24 @@ View future plans in the [Roadmap](#roadmap) section.
7777
3. Choose how to interact with the container:
7878
* Run a single command and exit:
7979
```bash
80-
docker run --rm -it digitalghostdev/poke-cli:v1.3.3 <command> [subcommand] flag]
80+
docker run --rm -it digitalghostdev/poke-cli:v1.4.0 <command> [subcommand] flag]
8181
```
8282
* Enter the container and use its shell:
8383
```bash
84-
docker run --rm -it --name poke-cli --entrypoint /bin/sh digitalghostdev/poke-cli:v1.3.3 -c "cd /app && exec sh"
84+
docker run --rm -it --name poke-cli --entrypoint /bin/sh digitalghostdev/poke-cli:v1.4.0 -c "cd /app && exec sh"
8585
# placed into the /app directory, run the program with './poke-cli'
8686
# example: ./poke-cli ability swift-swim
8787
```
8888

8989
### Homebrew
90-
```bash
91-
brew install --cask digitalghost-dev/tap/poke-cli
92-
93-
# verify
94-
poke-cli -v
95-
```
90+
1. Install the Cask:
91+
```bash
92+
brew install --cask digitalghost-dev/tap/poke-cli
93+
````
94+
2. Verify install!
95+
```bash
96+
poke-cli -v
97+
```
9698

9799
### Source
98100

@@ -121,6 +123,7 @@ By running `poke-cli [-h | --help]`, it'll display information on how to use the
121123
│ │
122124
│ COMMANDS: │
123125
│ ability Get details about an ability │
126+
│ item Get details about an item │
124127
│ move Get details about a move │
125128
│ natures Get details about all natures │
126129
│ pokemon Get details about a Pokémon │
@@ -130,6 +133,9 @@ By running `poke-cli [-h | --help]`, it'll display information on how to use the
130133
│ hint: when calling a resource with a space, use a hyphen │
131134
│ example: poke-cli ability strong-jaw │
132135
│ example: poke-cli pokemon flutter-mane │
136+
│ │
137+
│ ↓ ctrl/cmd + click for docs/guides │
138+
│ docs.poke-cli.com │
133139
╰──────────────────────────────────────────────────────────╯
134140
```
135141
@@ -138,20 +144,25 @@ By running `poke-cli [-h | --help]`, it'll display information on how to use the
138144
## Roadmap
139145
Below is a list of the planned/completed commands and flags:
140146
141-
- [x] `ability`: get data about a specific ability.
147+
- [x] `ability`: get data about an ability.
142148
- [x] `-p | --pokemon`: display Pokémon that learn this ability.
143-
- [ ] `berry`: get data about a specific berry.
144-
- [ ] `item`: get data about a specific item.
145-
- [x] `move`: get data about a specific move.
149+
- [ ] `berry`: get data about a berry.
150+
- [x] `item`: get data about an item.
151+
- [x] `move`: get data about a move.
146152
- [ ] `-p | --pokemon`: display Pokémon that learn this move.
147153
- [x] `natures`: get data about natures.
148-
- [x] `pokemon`: get data about a specific Pokémon.
154+
- [x] `pokemon`: get data about a Pokémon.
149155
- [x] `-a | --abilities`: display the Pokémon's abilities.
150156
- [x] `-i | --image`: display a pixel image of the Pokémon.
151157
- [x] `-s | --stats`: display the Pokémon's base stats.
152158
- [x] `-t | --types`: display the Pokémon's typing.
153159
- [x] `-m | --moves`: display learnable moves.
154-
- [x] `search`: search for a resource (`ability`, `berry`, `pokemon`, `move`)
160+
- [ ] `search`: search for a resource
161+
- [x] `ability`
162+
- [ ] `berry`
163+
- [ ] `item`
164+
- [x] `move`
165+
- [x] `pokemon`
155166
- [ ] `speed`: compare speed stats between two Pokémon.
156167
- [x] `types`: get data about a specific typing.
157168

cli.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"flag"
55
"fmt"
66
"github.com/digitalghost-dev/poke-cli/cmd/ability"
7+
"github.com/digitalghost-dev/poke-cli/cmd/item"
78
"github.com/digitalghost-dev/poke-cli/cmd/move"
89
"github.com/digitalghost-dev/poke-cli/cmd/natures"
910
"github.com/digitalghost-dev/poke-cli/cmd/pokemon"
@@ -66,6 +67,7 @@ func runCLI(args []string) int {
6667
fmt.Sprintf("\n\t%-15s %s", "-v, --version", "Prints the current version"),
6768
"\n\n", styling.StyleBold.Render("COMMANDS:"),
6869
fmt.Sprintf("\n\t%-15s %s", "ability", "Get details about an ability"),
70+
fmt.Sprintf("\n\t%-15s %s", "item", "Get details about an item"),
6971
fmt.Sprintf("\n\t%-15s %s", "move", "Get details about a move"),
7072
fmt.Sprintf("\n\t%-15s %s", "natures", "Get details about all natures"),
7173
fmt.Sprintf("\n\t%-15s %s", "pokemon", "Get details about a Pokémon"),
@@ -99,6 +101,7 @@ func runCLI(args []string) int {
99101

100102
commands := map[string]func() int{
101103
"ability": utils.HandleCommandOutput(ability.AbilityCommand),
104+
"item": utils.HandleCommandOutput(item.ItemCommand),
102105
"move": utils.HandleCommandOutput(move.MoveCommand),
103106
"natures": utils.HandleCommandOutput(natures.NaturesCommand),
104107
"pokemon": utils.HandleCommandOutput(pokemon.PokemonCommand),
@@ -133,6 +136,7 @@ func runCLI(args []string) int {
133136
fmt.Sprintf("\n\t%-15s", fmt.Sprintf("'%s' is not a valid command.\n", cmdArg)),
134137
styling.StyleBold.Render("\nCommands:"),
135138
fmt.Sprintf("\n\t%-15s %s", "ability", "Get details about an ability"),
139+
fmt.Sprintf("\n\t%-15s %s", "item", "Get details about an item"),
136140
fmt.Sprintf("\n\t%-15s %s", "move", "Get details about a move"),
137141
fmt.Sprintf("\n\t%-15s %s", "natures", "Get details about all natures"),
138142
fmt.Sprintf("\n\t%-15s %s", "pokemon", "Get details about a Pokémon"),

cmd/item/item.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package item
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"github.com/charmbracelet/lipgloss"
7+
"github.com/digitalghost-dev/poke-cli/cmd/utils"
8+
"github.com/digitalghost-dev/poke-cli/connections"
9+
"github.com/digitalghost-dev/poke-cli/structs"
10+
"github.com/digitalghost-dev/poke-cli/styling"
11+
"golang.org/x/text/cases"
12+
"golang.org/x/text/language"
13+
"os"
14+
"strings"
15+
)
16+
17+
func ItemCommand() (string, error) {
18+
var output strings.Builder
19+
20+
flag.Usage = func() {
21+
helpMessage := styling.HelpBorder.Render(
22+
"Get details about a specific item.\n\n",
23+
styling.StyleBold.Render("USAGE:"),
24+
fmt.Sprintf("\n\t%s %s %s %s", "poke-cli", styling.StyleBold.Render("item"), "<item-name>", "[flag]"),
25+
fmt.Sprintf("\n\t%-30s", styling.StyleItalic.Render("Use a hyphen when typing a name with a space.")),
26+
"\n\n",
27+
styling.StyleBold.Render("FLAGS:"),
28+
fmt.Sprintf("\n\t%-30s %s", "-h, --help", "Prints the help menu."),
29+
)
30+
output.WriteString(helpMessage)
31+
}
32+
33+
args := os.Args
34+
35+
flag.Parse()
36+
37+
if len(os.Args) == 3 && (os.Args[2] == "-h" || os.Args[2] == "--help") {
38+
flag.Usage()
39+
return output.String(), nil
40+
}
41+
42+
if err := utils.ValidateItemArgs(os.Args); err != nil {
43+
output.WriteString(err.Error())
44+
return output.String(), err
45+
}
46+
47+
endpoint := strings.ToLower(args[1])
48+
itemName := strings.ToLower(args[2])
49+
50+
itemStruct, itemName, err := connections.ItemApiCall(endpoint, itemName, connections.APIURL)
51+
if err != nil {
52+
if os.Getenv("GO_TESTING") != "1" {
53+
fmt.Fprintln(os.Stderr, err)
54+
os.Exit(1)
55+
}
56+
return err.Error(), nil
57+
}
58+
59+
itemInfoContainer(&output, itemStruct, itemName)
60+
61+
return output.String(), nil
62+
}
63+
64+
func itemInfoContainer(output *strings.Builder, itemStruct structs.ItemJSONStruct, itemName string) {
65+
capitalizedItem := styling.StyleBold.Render(cases.Title(language.English).String(strings.ReplaceAll(itemName, "-", " ")))
66+
itemCost := fmt.Sprintf("Cost: %d", itemStruct.Cost)
67+
itemCategory := "Category: " + cases.Title(language.English).String(strings.ReplaceAll(itemStruct.Category.Name, "-", " "))
68+
69+
docStyle := lipgloss.NewStyle().
70+
Padding(1, 2).
71+
BorderStyle(lipgloss.ThickBorder()).
72+
BorderForeground(lipgloss.AdaptiveColor{Light: "#444", Dark: "#EEE"}).
73+
Width(32)
74+
75+
var flavorTextEntry string
76+
var missingData string
77+
var fullDoc string
78+
79+
if len(itemStruct.FlavorTextEntries) == 0 {
80+
missingData = styling.StyleItalic.Render("Missing data from API")
81+
fullDoc = lipgloss.JoinVertical(lipgloss.Top, capitalizedItem, itemCost, itemCategory, "---", "Description:", missingData)
82+
} else {
83+
for _, entry := range itemStruct.FlavorTextEntries {
84+
if entry.Language.Name == "en" && entry.VersionGroup.Name == "sword-shield" {
85+
if entry.Text != "" {
86+
flavorTextEntry = entry.Text
87+
fullDoc = lipgloss.JoinVertical(lipgloss.Top, capitalizedItem, itemCost, itemCategory, "---", "Description:", flavorTextEntry)
88+
break
89+
}
90+
}
91+
}
92+
}
93+
94+
output.WriteString(docStyle.Render(fullDoc))
95+
output.WriteString("\n")
96+
}

cmd/item/item_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package item
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 TestItemCommand(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+
expectedError bool
29+
}{
30+
{
31+
name: "Item help flag",
32+
args: []string{"item", "--help"},
33+
expectedOutput: utils.LoadGolden(t, "item_help.golden"),
34+
},
35+
{
36+
name: "Item help flag",
37+
args: []string{"item", "-h"},
38+
expectedOutput: utils.LoadGolden(t, "item_help.golden"),
39+
},
40+
{
41+
name: "Select 'choice-band' as item",
42+
args: []string{"item", "choice-band"},
43+
expectedOutput: utils.LoadGolden(t, "item.golden"),
44+
},
45+
{
46+
name: "Select 'clear-amulet' as item with missing data",
47+
args: []string{"item", "clear-amulet"},
48+
expectedOutput: utils.LoadGolden(t, "item_missing_data.golden"),
49+
},
50+
{
51+
name: "Too many arguments",
52+
args: []string{"item", "dubious-disc", "--help"},
53+
expectedOutput: utils.LoadGolden(t, "item_too_many_args.golden"),
54+
expectedError: true,
55+
},
56+
}
57+
58+
for _, tt := range tests {
59+
t.Run(tt.name, func(t *testing.T) {
60+
originalArgs := os.Args
61+
os.Args = append([]string{"poke-cli"}, tt.args...)
62+
defer func() { os.Args = originalArgs }()
63+
64+
output, _ := ItemCommand()
65+
cleanOutput := styling.StripANSI(output)
66+
67+
assert.Equal(t, tt.expectedOutput, cleanOutput, "Output should match expected")
68+
})
69+
}
70+
}

cmd/move/move_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestMoveCommand(t *testing.T) {
3838
expectedOutput: utils.LoadGolden(t, "move_help.golden"),
3939
},
4040
{
41-
name: "Select 'Shadow-Ball' as move",
41+
name: "Select 'shadow-ball' as move",
4242
args: []string{"move", "shadow-ball"},
4343
expectedOutput: utils.LoadGolden(t, "move.golden"),
4444
},

cmd/natures/natures.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
func NaturesCommand() (string, error) {
1515
var output strings.Builder
1616

17-
// Define the usage function
1817
flag.Usage = func() {
1918
helpMessage := styling.HelpBorder.Render(
2019
"Get details about all natures.\n\n",

cmd/pokemon/pokemon.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ func PokemonCommand() (string, error) {
104104

105105
// Call the ImageFlag function with the specified size
106106
if err := flags.ImageFlag(&output, endpoint, pokemonName, size); err != nil {
107-
output.WriteString(fmt.Sprintf("error parsing flags: %v\n", err))
108-
return "", fmt.Errorf("error parsing flags: %w", err)
107+
output.WriteString(fmt.Sprintf("%v\n", err))
108+
return output.String(), fmt.Errorf("%w", err)
109109
}
110110
}
111111

0 commit comments

Comments
 (0)