Skip to content
Merged

1.4.0 #165

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e1d0b58
updating test data
digitalghost-dev Jul 4, 2025
1d949e8
updating test data
digitalghost-dev Jul 6, 2025
a15cff5
adding item command (#158)
digitalghost-dev Jul 6, 2025
d523012
updating version numbers
digitalghost-dev Jul 6, 2025
a81777f
updating tests
digitalghost-dev Jul 7, 2025
af4b9b7
changed quitting behavior (#159)
digitalghost-dev Jul 7, 2025
6afda88
adding API call for item endpoint (#158)
digitalghost-dev Jul 7, 2025
5bea864
updating dependencies, retracting v1.3.4
digitalghost-dev Jul 7, 2025
8ebb11b
updating version number, checking OS during post-hook
digitalghost-dev Jul 7, 2025
e9231f9
updating extenstion name
digitalghost-dev Jul 7, 2025
97058c8
fixing golangci-lint issue
digitalghost-dev Jul 7, 2025
e16902f
adding missing type from selection list (#160)
digitalghost-dev Jul 7, 2025
e047506
adding struct for item endpoint (#158)
digitalghost-dev Jul 7, 2025
f589b62
adding item endpoint
digitalghost-dev Jul 7, 2025
0b1fc2f
updating tests
digitalghost-dev Jul 7, 2025
5cba995
adding item references (#158)
digitalghost-dev Jul 7, 2025
10b459a
updating version numbers and roadmap
digitalghost-dev Jul 7, 2025
a36e90e
adding 'apk upgrade' to fix outdated vulnerabilities, updating to alp…
digitalghost-dev Jul 7, 2025
64ae85f
updating tests
digitalghost-dev Jul 7, 2025
fffdace
adding test for --move flag
digitalghost-dev Jul 7, 2025
0830a0d
adding validation checker (#158)
digitalghost-dev Jul 7, 2025
fdc1602
removing comments
digitalghost-dev Jul 8, 2025
409187e
adding reusable function (#163)
digitalghost-dev Jul 8, 2025
37be374
updating tests
digitalghost-dev Jul 8, 2025
6ece3a7
removing comments
digitalghost-dev Jul 8, 2025
1ff7ea4
removing fullURL from being printed
digitalghost-dev Jul 8, 2025
4fb85ba
adding test
digitalghost-dev Jul 8, 2025
978f516
updating test data
digitalghost-dev Jul 9, 2025
20c7ac8
printing error message when using non-valid image size (#164)
digitalghost-dev Jul 9, 2025
71d7cc7
updating error messaging
digitalghost-dev Jul 9, 2025
937c522
fixing typo
digitalghost-dev Jul 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ on:
- main

env:
VERSION_NUMBER: 'v1.3.3'
VERSION_NUMBER: 'v1.4.0'
DOCKERHUB_REGISTRY_NAME: 'digitalghostdev/poke-cli'
AWS_REGION: 'us-west-2'

Expand Down
6 changes: 3 additions & 3 deletions .goreleaser.yaml → .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ builds:
- windows
- darwin
ldflags:
- -s -w -X main.version=v1.3.3
- -s -w -X main.version=v1.4.0

archives:
- formats: [ 'zip' ]
Expand All @@ -28,7 +28,7 @@ archives:
# use zip for windows archives
format_overrides:
- goos: windows
- formats: [ 'zip' ]
formats: [ 'zip' ]

changelog:
sort: asc
Expand All @@ -51,6 +51,6 @@ homebrew_casks:
hooks:
post:
install: |
if system_command("/usr/bin/xattr", args: ["-h"]).exit_status == 0
if OS.mac? && system_command("/usr/bin/xattr", args: ["-h"]).exit_status == 0
system_command "/usr/bin/xattr", args: ["-dr", "com.apple.quarantine", "#{staged_path}/poke-cli"]
end
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# build 1
FROM golang:1.24.4-alpine3.21 AS build
FROM golang:1.24.4-alpine3.22 AS build

WORKDIR /app

Expand All @@ -8,13 +8,14 @@ RUN go mod download

COPY . .

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

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

# Install only necessary packages and remove them after use
RUN apk add --no-cache shadow && \
RUN apk upgrade && \
apk add --no-cache shadow && \
addgroup -S poke_group && adduser -S poke_user -G poke_group && \
sed -i 's/^root:.*/root:!*:0:0:root:\/root:\/sbin\/nologin/' /etc/passwd && \
apk del shadow
Expand Down
41 changes: 26 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<img height="250" width="350" src="pokemon.svg" alt="pokemon-logo"/>
<h1>Pokémon CLI</h1>
<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">
<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">
<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">
<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">
</div>
<div align="center">
Expand Down Expand Up @@ -77,22 +77,24 @@ View future plans in the [Roadmap](#roadmap) section.
3. Choose how to interact with the container:
* Run a single command and exit:
```bash
docker run --rm -it digitalghostdev/poke-cli:v1.3.3 <command> [subcommand] flag]
docker run --rm -it digitalghostdev/poke-cli:v1.4.0 <command> [subcommand] flag]
```
* Enter the container and use its shell:
```bash
docker run --rm -it --name poke-cli --entrypoint /bin/sh digitalghostdev/poke-cli:v1.3.3 -c "cd /app && exec sh"
docker run --rm -it --name poke-cli --entrypoint /bin/sh digitalghostdev/poke-cli:v1.4.0 -c "cd /app && exec sh"
# placed into the /app directory, run the program with './poke-cli'
# example: ./poke-cli ability swift-swim
```

### Homebrew
```bash
brew install --cask digitalghost-dev/tap/poke-cli

# verify
poke-cli -v
```
1. Install the Cask:
```bash
brew install --cask digitalghost-dev/tap/poke-cli
````
2. Verify install!
```bash
poke-cli -v
```

### Source

Expand Down Expand Up @@ -121,6 +123,7 @@ By running `poke-cli [-h | --help]`, it'll display information on how to use the
│ │
│ COMMANDS: │
│ ability Get details about an ability │
│ item Get details about an item │
│ move Get details about a move │
│ natures Get details about all natures │
│ pokemon Get details about a Pokémon │
Expand All @@ -130,6 +133,9 @@ By running `poke-cli [-h | --help]`, it'll display information on how to use the
│ hint: when calling a resource with a space, use a hyphen │
│ example: poke-cli ability strong-jaw │
│ example: poke-cli pokemon flutter-mane │
│ │
│ ↓ ctrl/cmd + click for docs/guides │
│ docs.poke-cli.com │
╰──────────────────────────────────────────────────────────╯
```

Expand All @@ -138,20 +144,25 @@ By running `poke-cli [-h | --help]`, it'll display information on how to use the
## Roadmap
Below is a list of the planned/completed commands and flags:

- [x] `ability`: get data about a specific ability.
- [x] `ability`: get data about an ability.
- [x] `-p | --pokemon`: display Pokémon that learn this ability.
- [ ] `berry`: get data about a specific berry.
- [ ] `item`: get data about a specific item.
- [x] `move`: get data about a specific move.
- [ ] `berry`: get data about a berry.
- [x] `item`: get data about an item.
- [x] `move`: get data about a move.
- [ ] `-p | --pokemon`: display Pokémon that learn this move.
- [x] `natures`: get data about natures.
- [x] `pokemon`: get data about a specific Pokémon.
- [x] `pokemon`: get data about a Pokémon.
- [x] `-a | --abilities`: display the Pokémon's abilities.
- [x] `-i | --image`: display a pixel image of the Pokémon.
- [x] `-s | --stats`: display the Pokémon's base stats.
- [x] `-t | --types`: display the Pokémon's typing.
- [x] `-m | --moves`: display learnable moves.
- [x] `search`: search for a resource (`ability`, `berry`, `pokemon`, `move`)
- [ ] `search`: search for a resource
- [x] `ability`
- [ ] `berry`
- [ ] `item`
- [x] `move`
- [x] `pokemon`
- [ ] `speed`: compare speed stats between two Pokémon.
- [x] `types`: get data about a specific typing.

Expand Down
4 changes: 4 additions & 0 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"flag"
"fmt"
"github.com/digitalghost-dev/poke-cli/cmd/ability"
"github.com/digitalghost-dev/poke-cli/cmd/item"
"github.com/digitalghost-dev/poke-cli/cmd/move"
"github.com/digitalghost-dev/poke-cli/cmd/natures"
"github.com/digitalghost-dev/poke-cli/cmd/pokemon"
Expand Down Expand Up @@ -66,6 +67,7 @@
fmt.Sprintf("\n\t%-15s %s", "-v, --version", "Prints the current version"),
"\n\n", styling.StyleBold.Render("COMMANDS:"),
fmt.Sprintf("\n\t%-15s %s", "ability", "Get details about an ability"),
fmt.Sprintf("\n\t%-15s %s", "item", "Get details about an item"),
fmt.Sprintf("\n\t%-15s %s", "move", "Get details about a move"),
fmt.Sprintf("\n\t%-15s %s", "natures", "Get details about all natures"),
fmt.Sprintf("\n\t%-15s %s", "pokemon", "Get details about a Pokémon"),
Expand Down Expand Up @@ -99,6 +101,7 @@

commands := map[string]func() int{
"ability": utils.HandleCommandOutput(ability.AbilityCommand),
"item": utils.HandleCommandOutput(item.ItemCommand),
"move": utils.HandleCommandOutput(move.MoveCommand),
"natures": utils.HandleCommandOutput(natures.NaturesCommand),
"pokemon": utils.HandleCommandOutput(pokemon.PokemonCommand),
Expand Down Expand Up @@ -133,6 +136,7 @@
fmt.Sprintf("\n\t%-15s", fmt.Sprintf("'%s' is not a valid command.\n", cmdArg)),
styling.StyleBold.Render("\nCommands:"),
fmt.Sprintf("\n\t%-15s %s", "ability", "Get details about an ability"),
fmt.Sprintf("\n\t%-15s %s", "item", "Get details about an item"),

Check warning on line 139 in cli.go

View check run for this annotation

Codecov / codecov/patch

cli.go#L139

Added line #L139 was not covered by tests
fmt.Sprintf("\n\t%-15s %s", "move", "Get details about a move"),
fmt.Sprintf("\n\t%-15s %s", "natures", "Get details about all natures"),
fmt.Sprintf("\n\t%-15s %s", "pokemon", "Get details about a Pokémon"),
Expand Down
96 changes: 96 additions & 0 deletions cmd/item/item.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package item

import (
"flag"
"fmt"
"github.com/charmbracelet/lipgloss"
"github.com/digitalghost-dev/poke-cli/cmd/utils"
"github.com/digitalghost-dev/poke-cli/connections"
"github.com/digitalghost-dev/poke-cli/structs"
"github.com/digitalghost-dev/poke-cli/styling"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"os"
"strings"
)

func ItemCommand() (string, error) {
var output strings.Builder

flag.Usage = func() {
helpMessage := styling.HelpBorder.Render(
"Get details about a specific item.\n\n",
styling.StyleBold.Render("USAGE:"),
fmt.Sprintf("\n\t%s %s %s %s", "poke-cli", styling.StyleBold.Render("item"), "<item-name>", "[flag]"),
fmt.Sprintf("\n\t%-30s", styling.StyleItalic.Render("Use a hyphen when typing a name with a space.")),
"\n\n",
styling.StyleBold.Render("FLAGS:"),
fmt.Sprintf("\n\t%-30s %s", "-h, --help", "Prints the help menu."),
)
output.WriteString(helpMessage)
}

args := os.Args

flag.Parse()

if len(os.Args) == 3 && (os.Args[2] == "-h" || os.Args[2] == "--help") {
flag.Usage()
return output.String(), nil
}

if err := utils.ValidateItemArgs(os.Args); err != nil {
output.WriteString(err.Error())
return output.String(), err
}

endpoint := strings.ToLower(args[1])
itemName := strings.ToLower(args[2])

itemStruct, itemName, err := connections.ItemApiCall(endpoint, itemName, connections.APIURL)
if err != nil {
if os.Getenv("GO_TESTING") != "1" {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
return err.Error(), nil

Check warning on line 56 in cmd/item/item.go

View check run for this annotation

Codecov / codecov/patch

cmd/item/item.go#L52-L56

Added lines #L52 - L56 were not covered by tests
}

itemInfoContainer(&output, itemStruct, itemName)

return output.String(), nil
}

func itemInfoContainer(output *strings.Builder, itemStruct structs.ItemJSONStruct, itemName string) {
capitalizedItem := styling.StyleBold.Render(cases.Title(language.English).String(strings.ReplaceAll(itemName, "-", " ")))
itemCost := fmt.Sprintf("Cost: %d", itemStruct.Cost)
itemCategory := "Category: " + cases.Title(language.English).String(strings.ReplaceAll(itemStruct.Category.Name, "-", " "))

docStyle := lipgloss.NewStyle().
Padding(1, 2).
BorderStyle(lipgloss.ThickBorder()).
BorderForeground(lipgloss.AdaptiveColor{Light: "#444", Dark: "#EEE"}).
Width(32)

var flavorTextEntry string
var missingData string
var fullDoc string

if len(itemStruct.FlavorTextEntries) == 0 {
missingData = styling.StyleItalic.Render("Missing data from API")
fullDoc = lipgloss.JoinVertical(lipgloss.Top, capitalizedItem, itemCost, itemCategory, "---", "Description:", missingData)
} else {
for _, entry := range itemStruct.FlavorTextEntries {
if entry.Language.Name == "en" && entry.VersionGroup.Name == "sword-shield" {
if entry.Text != "" {
flavorTextEntry = entry.Text
fullDoc = lipgloss.JoinVertical(lipgloss.Top, capitalizedItem, itemCost, itemCategory, "---", "Description:", flavorTextEntry)
break
}
}
}
}

output.WriteString(docStyle.Render(fullDoc))
output.WriteString("\n")
}
70 changes: 70 additions & 0 deletions cmd/item/item_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package item

import (
"github.com/digitalghost-dev/poke-cli/cmd/utils"
"github.com/digitalghost-dev/poke-cli/styling"
"github.com/stretchr/testify/assert"
"os"
"testing"
)

func TestItemCommand(t *testing.T) {
err := os.Setenv("GO_TESTING", "1")
if err != nil {
t.Fatalf("Failed to set GO_TESTING env var: %v", err)
}

defer func() {
err := os.Unsetenv("GO_TESTING")
if err != nil {
t.Logf("Warning: failed to unset GO_TESTING: %v", err)
}
}()

tests := []struct {
name string
args []string
expectedOutput string
expectedError bool
}{
{
name: "Item help flag",
args: []string{"item", "--help"},
expectedOutput: utils.LoadGolden(t, "item_help.golden"),
},
{
name: "Item help flag",
args: []string{"item", "-h"},
expectedOutput: utils.LoadGolden(t, "item_help.golden"),
},
{
name: "Select 'choice-band' as item",
args: []string{"item", "choice-band"},
expectedOutput: utils.LoadGolden(t, "item.golden"),
},
{
name: "Select 'clear-amulet' as item with missing data",
args: []string{"item", "clear-amulet"},
expectedOutput: utils.LoadGolden(t, "item_missing_data.golden"),
},
{
name: "Too many arguments",
args: []string{"item", "dubious-disc", "--help"},
expectedOutput: utils.LoadGolden(t, "item_too_many_args.golden"),
expectedError: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
originalArgs := os.Args
os.Args = append([]string{"poke-cli"}, tt.args...)
defer func() { os.Args = originalArgs }()

output, _ := ItemCommand()
cleanOutput := styling.StripANSI(output)

assert.Equal(t, tt.expectedOutput, cleanOutput, "Output should match expected")
})
}
}
2 changes: 1 addition & 1 deletion cmd/move/move_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestMoveCommand(t *testing.T) {
expectedOutput: utils.LoadGolden(t, "move_help.golden"),
},
{
name: "Select 'Shadow-Ball' as move",
name: "Select 'shadow-ball' as move",
args: []string{"move", "shadow-ball"},
expectedOutput: utils.LoadGolden(t, "move.golden"),
},
Expand Down
1 change: 0 additions & 1 deletion cmd/natures/natures.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
func NaturesCommand() (string, error) {
var output strings.Builder

// Define the usage function
flag.Usage = func() {
helpMessage := styling.HelpBorder.Render(
"Get details about all natures.\n\n",
Expand Down
4 changes: 2 additions & 2 deletions cmd/pokemon/pokemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ func PokemonCommand() (string, error) {

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

Expand Down
Loading
Loading