Skip to content
Merged

1.2.2 #135

Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -26,7 +26,7 @@ on:
- main

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

Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yaml
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.2.1
- -s -w -X main.version=v1.2.2

archives:
- format: tar.gz
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN go mod download

COPY . .

RUN go build -ldflags "-X main.version=v1.2.1" -o poke-cli .
RUN go build -ldflags "-X main.version=v1.2.2" -o poke-cli .

# build 2
FROM --platform=$BUILDPLATFORM alpine:latest
Expand Down
8 changes: 4 additions & 4 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.2.1?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.2.2?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 @@ -76,11 +76,11 @@ 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.2.1 <command> [subcommand] flag]
docker run --rm -it digitalghostdev/poke-cli:v1.2.2 <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.2.1 -c "cd /app && exec sh"
docker run --rm -it --name poke-cli --entrypoint /bin/sh digitalghostdev/poke-cli:v1.2.2 -c "cd /app && exec sh"
# placed into the /app directory, run the program with './poke-cli'
# example: ./poke-cli ability swift-swim
```
Expand Down Expand Up @@ -145,7 +145,7 @@ Below is a list of the planned/completed commands and flags:
- [x] `move`: get data about a specific move.
- [ ] `-p | --pokemon`: display Pokémon that learn this move.
- [x] `natures`: get data about natures.
- [ ] `pokemon`: get data about a specific Pokémon.
- [x] `pokemon`: get data about a specific 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.
Expand Down
3 changes: 2 additions & 1 deletion cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/digitalghost-dev/poke-cli/cmd"
"github.com/digitalghost-dev/poke-cli/cmd/move"
"github.com/digitalghost-dev/poke-cli/cmd/search"
"github.com/digitalghost-dev/poke-cli/cmd/types"
"github.com/digitalghost-dev/poke-cli/flags"
"github.com/digitalghost-dev/poke-cli/styling"
"os"
Expand Down Expand Up @@ -92,7 +93,7 @@ func runCLI(args []string) int {
"move": move.MoveCommand,
"natures": cmd.NaturesCommand,
"pokemon": cmd.PokemonCommand,
"types": cmd.TypesCommand,
"types": types.TypesCommand,
"search": search.SearchCommand,
}

Expand Down
5 changes: 5 additions & 0 deletions cmd/ability.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ func AbilityCommand() {

flag.Parse()

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

if err := ValidateAbilityArgs(args); err != nil {
fmt.Println(err.Error())
if os.Getenv("GO_TESTING") != "1" {
Expand Down
16 changes: 11 additions & 5 deletions cmd/move/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,23 @@
helpMessage := styling.HelpBorder.Render(
"Get details about a specific move.\n\n",
styling.StyleBold.Render("USAGE:"),
fmt.Sprintf("\n\t%s %s %s %s", "poke-cli", styling.StyleBold.Render("move"), "<move-name>", "[flag]"),
fmt.Sprintf("\n\t%-20s", styling.StyleItalic.Render("Use a hyphen when typing a name with a space.")),
"\n\n",
styling.StyleBold.Render("FLAGS:"),
fmt.Sprintf("\n\t%-20s %s", "-h, --help", "Prints the help menu."),
"\n\t"+"poke-cli"+" "+styling.StyleBold.Render("move")+" <move-name>",
"\n\n"+styling.StyleItalic.Render("Use a hyphen when typing a name with a space."),
)
fmt.Println(helpMessage)
}

flag.Parse()

// Check for help flag
if len(os.Args) == 3 && (os.Args[2] == "-h" || os.Args[2] == "--help") {
flag.Usage()

if flag.Lookup("test.v") == nil {
os.Exit(0)
}

Check warning on line 37 in cmd/move/move.go

View check run for this annotation

Codecov / codecov/patch

cmd/move/move.go#L36-L37

Added lines #L36 - L37 were not covered by tests
}

if err := cmd.ValidateMoveArgs(os.Args); err != nil {
fmt.Println(err.Error())
os.Exit(1)
Expand Down
12 changes: 10 additions & 2 deletions cmd/natures.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"os"
)

var osExit = os.Exit

func NaturesCommand() {
flag.Usage = func() {
helpMessage := styling.HelpBorder.Render(
Expand All @@ -21,9 +23,15 @@ func NaturesCommand() {

flag.Parse()

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

if err := ValidateNaturesArgs(os.Args); err != nil {
fmt.Println(err.Error())
os.Exit(1)
osExit(1)
return
}

fmt.Println("Natures affect the growth of a Pokémon.\n" +
Expand All @@ -48,7 +56,7 @@ func NaturesCommand() {
Rows(chart...).
StyleFunc(func(row, col int) lipgloss.Style {
return lipgloss.NewStyle().
Padding(0, 1) // This styles the border color
Padding(0, 1)
})

fmt.Println(t.Render())
Expand Down
104 changes: 58 additions & 46 deletions cmd/natures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,33 @@ package cmd

import (
"bytes"
"fmt"
"github.com/digitalghost-dev/poke-cli/styling"
"github.com/stretchr/testify/assert"
"os"
"strings"
"testing"
)

var exitCode int

func fakeExit(code int) {
exitCode = code
panic("exit")
}

func captureNaturesOutput(f func()) string {
// Create a pipe to capture standard output
r, w, _ := os.Pipe()
defer func(r *os.File) {
err := r.Close()
if err != nil {
fmt.Println(err)
}
}(r)

// Redirect os.Stdout to the write end of the pipe
defer func() {
_ = r.Close()
}()

oldStdout := os.Stdout
os.Stdout = w
defer func() { os.Stdout = oldStdout }()

// Run the function
f()

// Close the write end of the pipe
err := w.Close()
if err != nil {
return ""
}
_ = w.Close()

// Read the captured output
var buf bytes.Buffer
_, _ = buf.ReadFrom(r)
return buf.String()
Expand All @@ -59,46 +54,56 @@ func TestNaturesCommand(t *testing.T) {
expectedError: false,
},
{
name: "Valid Execution",
name: "Invalid extra argument",
args: []string{"natures", "extra"},
expectedOutput: styling.StripANSI(styling.ErrorBorder.Render(styling.ErrorColor.Render("Error!")+"\nThe only currently available options\nafter <natures> command are '-h' or '--help'")) + "\n",
expectedError: true,
},
{
name: "Full Natures output with table",
args: []string{"natures"},
expectedOutput: styling.StripANSI(
"Natures affect the growth of a Pokémon.\n" +
"Each nature increases one of its stats by 10% and decreases one by 10%.\n" +
"Five natures increase and decrease the same stat and therefore have no effect.\n\n" +
"Nature Chart:\n" +
"┌──────────┬─────────┬──────────┬──────────┬──────────┬─────────┐\n" +
"│ │ -Attack │ -Defense │ -Sp. Atk │ -Sp. Def │ Speed │\n" +
"├──────────┼─────────┼──────────┼──────────┼──────────┼─────────┤\n" +
"│ +Attack │ Hardy │ Lonely │ Adamant │ Naughty │ Brave │\n" +
"├──────────┼─────────┼──────────┼──────────┼──────────┼─────────┤\n" +
"│ +Defense │ Bold │ Docile │ Impish │ Lax │ Relaxed │\n" +
"├──────────┼─────────┼──────────┼──────────┼──────────┼─────────┤\n" +
"│ +Sp. Atk │ Modest │ Mild │ Bashful │ Rash │ Quiet │\n" +
"├──────────┼─────────┼──────────┼──────────┼──────────┼─────────┤\n" +
"│ +Sp. Def │ Calm │ Gentle │ Careful │ Quirky │ Sassy │\n" +
"├──────────┼─────────┼──────────┼──────────┼──────────┼─────────┤\n" +
"│ Speed │ Timid │ Hasty │ Jolly │ Naive │ Serious │\n" +
"└──────────┴─────────┴──────────┴──────────┴──────────┴─────────┘\n"),
expectedOutput: "Natures affect the growth of a Pokémon.\n" +
"Each nature increases one of its stats by 10% and decreases one by 10%.\n" +
"Five natures increase and decrease the same stat and therefore have no effect.\n\n" +
"Nature Chart:\n" +
"┌──────────┬─────────┬──────────┬──────────┬──────────┬─────────┐\n" +
"│ │ -Attack │ -Defense │ -Sp. Atk │ -Sp. Def │ Speed │\n" +
"├──────────┼─────────┼──────────┼──────────┼──────────┼─────────┤\n" +
"│ +Attack │ Hardy │ Lonely │ Adamant │ Naughty │ Brave │\n" +
"├──────────┼─────────┼──────────┼──────────┼──────────┼─────────┤\n" +
"│ +Defense │ Bold │ Docile │ Impish │ Lax │ Relaxed │\n" +
"├──────────┼─────────┼──────────┼──────────┼──────────┼─────────┤\n" +
"│ +Sp. Atk │ Modest │ Mild │ Bashful │ Rash │ Quiet │\n" +
"├──────────┼─────────┼──────────┼──────────┼──────────┼─────────┤\n" +
"│ +Sp. Def │ Calm │ Gentle │ Careful │ Quirky │ Sassy │\n" +
"├──────────┼─────────┼──────────┼──────────┼──────────┼─────────┤\n" +
"│ Speed │ Timid │ Hasty │ Jolly │ Naive │ Serious │\n" +
"└──────────┴─────────┴──────────┴──────────┴──────────┴─────────┘\n",
expectedError: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Override osExit
oldExit := osExit
osExit = fakeExit
defer func() { osExit = oldExit }()

// Reset captured exit code
exitCode = 0

// Save original os.Args
originalArgs := os.Args
defer func() { os.Args = originalArgs }()

// Set os.Args for the test
os.Args = append([]string{"poke-cli"}, tt.args...)

// Capture the output
// Capture output
output := captureNaturesOutput(func() {
defer func() {
// Recover from os.Exit calls
if r := recover(); r != nil {
if !tt.expectedError {
t.Fatalf("Unexpected error: %v", r)
if r != "exit" {
t.Fatalf("Unexpected panic: %v", r)
}
}
}()
Expand All @@ -107,9 +112,16 @@ func TestNaturesCommand(t *testing.T) {

cleanOutput := styling.StripANSI(output)

// Check output
if !strings.Contains(cleanOutput, tt.expectedOutput) {
t.Errorf("Output mismatch.\nExpected to contain:\n%s\nGot:\n%s", tt.expectedOutput, output)
// Logging expected vs actual
t.Logf("Expected Output:\n%s", tt.expectedOutput)
t.Logf("Actual Output:\n%s", cleanOutput)

// Assertions
assert.Equal(t, tt.expectedOutput, cleanOutput, "Output should match expected")
if tt.expectedError {
assert.Equal(t, 1, exitCode, "Expected exit code 1 on error")
} else {
assert.Equal(t, 0, exitCode, "Expected no exit (code 0) on success")
}
})
}
Expand Down
5 changes: 5 additions & 0 deletions cmd/pokemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@

flag.Parse()

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

Check warning on line 63 in cmd/pokemon.go

View check run for this annotation

Codecov / codecov/patch

cmd/pokemon.go#L61-L63

Added lines #L61 - L63 were not covered by tests

err := ValidatePokemonArgs(args)
if err != nil {
fmt.Println(err.Error())
Expand Down
Loading