Skip to content

Commit b3f8802

Browse files
Merge pull request #135 from digitalghost-dev/1.2.2
1.2.2
2 parents 65a4646 + 5ba71b9 commit b3f8802

File tree

18 files changed

+445
-305
lines changed

18 files changed

+445
-305
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.1'
29+
VERSION_NUMBER: 'v1.2.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.2.1
17+
- -s -w -X main.version=v1.2.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.2.1" -o poke-cli .
11+
RUN go build -ldflags "-X main.version=v1.2.2" -o poke-cli .
1212

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

README.md

Lines changed: 4 additions & 4 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.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.2.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.2.1 <command> [subcommand] flag]
79+
docker run --rm -it digitalghostdev/poke-cli:v1.2.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.2.1 -c "cd /app && exec sh"
83+
docker run --rm -it --name poke-cli --entrypoint /bin/sh digitalghostdev/poke-cli:v1.2.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
```
@@ -145,7 +145,7 @@ Below is a list of the planned/completed commands and flags:
145145
- [x] `move`: get data about a specific move.
146146
- [ ] `-p | --pokemon`: display Pokémon that learn this move.
147147
- [x] `natures`: get data about natures.
148-
- [ ] `pokemon`: get data about a specific Pokémon.
148+
- [x] `pokemon`: get data about a specific Pokémon.
149149
- [x] `-a | --abilities`: display the Pokémon's abilities.
150150
- [x] `-i | --image`: display a pixel image of the Pokémon.
151151
- [x] `-s | --stats`: display the Pokémon's base stats.

cli.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/digitalghost-dev/poke-cli/cmd"
77
"github.com/digitalghost-dev/poke-cli/cmd/move"
88
"github.com/digitalghost-dev/poke-cli/cmd/search"
9+
"github.com/digitalghost-dev/poke-cli/cmd/types"
910
"github.com/digitalghost-dev/poke-cli/flags"
1011
"github.com/digitalghost-dev/poke-cli/styling"
1112
"os"
@@ -92,7 +93,7 @@ func runCLI(args []string) int {
9293
"move": move.MoveCommand,
9394
"natures": cmd.NaturesCommand,
9495
"pokemon": cmd.PokemonCommand,
95-
"types": cmd.TypesCommand,
96+
"types": types.TypesCommand,
9697
"search": search.SearchCommand,
9798
}
9899

cmd/ability.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ func AbilityCommand() {
3333

3434
flag.Parse()
3535

36+
if len(os.Args) == 3 && (os.Args[2] == "-h" || os.Args[2] == "--help") {
37+
flag.Usage()
38+
return
39+
}
40+
3641
if err := ValidateAbilityArgs(args); err != nil {
3742
fmt.Println(err.Error())
3843
if os.Getenv("GO_TESTING") != "1" {

cmd/move/move.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,23 @@ func MoveCommand() {
2020
helpMessage := styling.HelpBorder.Render(
2121
"Get details about a specific move.\n\n",
2222
styling.StyleBold.Render("USAGE:"),
23-
fmt.Sprintf("\n\t%s %s %s %s", "poke-cli", styling.StyleBold.Render("move"), "<move-name>", "[flag]"),
24-
fmt.Sprintf("\n\t%-20s", styling.StyleItalic.Render("Use a hyphen when typing a name with a space.")),
25-
"\n\n",
26-
styling.StyleBold.Render("FLAGS:"),
27-
fmt.Sprintf("\n\t%-20s %s", "-h, --help", "Prints the help menu."),
23+
"\n\t"+"poke-cli"+" "+styling.StyleBold.Render("move")+" <move-name>",
24+
"\n\n"+styling.StyleItalic.Render("Use a hyphen when typing a name with a space."),
2825
)
2926
fmt.Println(helpMessage)
3027
}
3128

3229
flag.Parse()
3330

31+
// Check for help flag
32+
if len(os.Args) == 3 && (os.Args[2] == "-h" || os.Args[2] == "--help") {
33+
flag.Usage()
34+
35+
if flag.Lookup("test.v") == nil {
36+
os.Exit(0)
37+
}
38+
}
39+
3440
if err := cmd.ValidateMoveArgs(os.Args); err != nil {
3541
fmt.Println(err.Error())
3642
os.Exit(1)

cmd/natures.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"os"
1010
)
1111

12+
var osExit = os.Exit
13+
1214
func NaturesCommand() {
1315
flag.Usage = func() {
1416
helpMessage := styling.HelpBorder.Render(
@@ -21,9 +23,15 @@ func NaturesCommand() {
2123

2224
flag.Parse()
2325

26+
if len(os.Args) == 3 && (os.Args[2] == "-h" || os.Args[2] == "--help") {
27+
flag.Usage()
28+
return
29+
}
30+
2431
if err := ValidateNaturesArgs(os.Args); err != nil {
2532
fmt.Println(err.Error())
26-
os.Exit(1)
33+
osExit(1)
34+
return
2735
}
2836

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

5462
fmt.Println(t.Render())

cmd/natures_test.go

Lines changed: 58 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,33 @@ package cmd
22

33
import (
44
"bytes"
5-
"fmt"
65
"github.com/digitalghost-dev/poke-cli/styling"
6+
"github.com/stretchr/testify/assert"
77
"os"
8-
"strings"
98
"testing"
109
)
1110

11+
var exitCode int
12+
13+
func fakeExit(code int) {
14+
exitCode = code
15+
panic("exit")
16+
}
17+
1218
func captureNaturesOutput(f func()) string {
13-
// Create a pipe to capture standard output
1419
r, w, _ := os.Pipe()
15-
defer func(r *os.File) {
16-
err := r.Close()
17-
if err != nil {
18-
fmt.Println(err)
19-
}
20-
}(r)
21-
22-
// Redirect os.Stdout to the write end of the pipe
20+
defer func() {
21+
_ = r.Close()
22+
}()
23+
2324
oldStdout := os.Stdout
2425
os.Stdout = w
2526
defer func() { os.Stdout = oldStdout }()
2627

27-
// Run the function
2828
f()
2929

30-
// Close the write end of the pipe
31-
err := w.Close()
32-
if err != nil {
33-
return ""
34-
}
30+
_ = w.Close()
3531

36-
// Read the captured output
3732
var buf bytes.Buffer
3833
_, _ = buf.ReadFrom(r)
3934
return buf.String()
@@ -59,46 +54,56 @@ func TestNaturesCommand(t *testing.T) {
5954
expectedError: false,
6055
},
6156
{
62-
name: "Valid Execution",
57+
name: "Invalid extra argument",
58+
args: []string{"natures", "extra"},
59+
expectedOutput: styling.StripANSI(styling.ErrorBorder.Render(styling.ErrorColor.Render("Error!")+"\nThe only currently available options\nafter <natures> command are '-h' or '--help'")) + "\n",
60+
expectedError: true,
61+
},
62+
{
63+
name: "Full Natures output with table",
6364
args: []string{"natures"},
64-
expectedOutput: styling.StripANSI(
65-
"Natures affect the growth of a Pokémon.\n" +
66-
"Each nature increases one of its stats by 10% and decreases one by 10%.\n" +
67-
"Five natures increase and decrease the same stat and therefore have no effect.\n\n" +
68-
"Nature Chart:\n" +
69-
"┌──────────┬─────────┬──────────┬──────────┬──────────┬─────────┐\n" +
70-
"│ │ -Attack │ -Defense │ -Sp. Atk │ -Sp. Def │ Speed │\n" +
71-
"├──────────┼─────────┼──────────┼──────────┼──────────┼─────────┤\n" +
72-
"│ +Attack │ Hardy │ Lonely │ Adamant │ Naughty │ Brave │\n" +
73-
"├──────────┼─────────┼──────────┼──────────┼──────────┼─────────┤\n" +
74-
"│ +Defense │ Bold │ Docile │ Impish │ Lax │ Relaxed │\n" +
75-
"├──────────┼─────────┼──────────┼──────────┼──────────┼─────────┤\n" +
76-
"│ +Sp. Atk │ Modest │ Mild │ Bashful │ Rash │ Quiet │\n" +
77-
"├──────────┼─────────┼──────────┼──────────┼──────────┼─────────┤\n" +
78-
"│ +Sp. Def │ Calm │ Gentle │ Careful │ Quirky │ Sassy │\n" +
79-
"├──────────┼─────────┼──────────┼──────────┼──────────┼─────────┤\n" +
80-
"│ Speed │ Timid │ Hasty │ Jolly │ Naive │ Serious │\n" +
81-
"└──────────┴─────────┴──────────┴──────────┴──────────┴─────────┘\n"),
65+
expectedOutput: "Natures affect the growth of a Pokémon.\n" +
66+
"Each nature increases one of its stats by 10% and decreases one by 10%.\n" +
67+
"Five natures increase and decrease the same stat and therefore have no effect.\n\n" +
68+
"Nature Chart:\n" +
69+
"┌──────────┬─────────┬──────────┬──────────┬──────────┬─────────┐\n" +
70+
"│ │ -Attack │ -Defense │ -Sp. Atk │ -Sp. Def │ Speed │\n" +
71+
"├──────────┼─────────┼──────────┼──────────┼──────────┼─────────┤\n" +
72+
"│ +Attack │ Hardy │ Lonely │ Adamant │ Naughty │ Brave │\n" +
73+
"├──────────┼─────────┼──────────┼──────────┼──────────┼─────────┤\n" +
74+
"│ +Defense │ Bold │ Docile │ Impish │ Lax │ Relaxed │\n" +
75+
"├──────────┼─────────┼──────────┼──────────┼──────────┼─────────┤\n" +
76+
"│ +Sp. Atk │ Modest │ Mild │ Bashful │ Rash │ Quiet │\n" +
77+
"├──────────┼─────────┼──────────┼──────────┼──────────┼─────────┤\n" +
78+
"│ +Sp. Def │ Calm │ Gentle │ Careful │ Quirky │ Sassy │\n" +
79+
"├──────────┼─────────┼──────────┼──────────┼──────────┼─────────┤\n" +
80+
"│ Speed │ Timid │ Hasty │ Jolly │ Naive │ Serious │\n" +
81+
"└──────────┴─────────┴──────────┴──────────┴──────────┴─────────┘\n",
8282
expectedError: false,
8383
},
8484
}
8585

8686
for _, tt := range tests {
8787
t.Run(tt.name, func(t *testing.T) {
88+
// Override osExit
89+
oldExit := osExit
90+
osExit = fakeExit
91+
defer func() { osExit = oldExit }()
92+
93+
// Reset captured exit code
94+
exitCode = 0
95+
8896
// Save original os.Args
8997
originalArgs := os.Args
9098
defer func() { os.Args = originalArgs }()
91-
92-
// Set os.Args for the test
9399
os.Args = append([]string{"poke-cli"}, tt.args...)
94100

95-
// Capture the output
101+
// Capture output
96102
output := captureNaturesOutput(func() {
97103
defer func() {
98-
// Recover from os.Exit calls
99104
if r := recover(); r != nil {
100-
if !tt.expectedError {
101-
t.Fatalf("Unexpected error: %v", r)
105+
if r != "exit" {
106+
t.Fatalf("Unexpected panic: %v", r)
102107
}
103108
}
104109
}()
@@ -107,9 +112,16 @@ func TestNaturesCommand(t *testing.T) {
107112

108113
cleanOutput := styling.StripANSI(output)
109114

110-
// Check output
111-
if !strings.Contains(cleanOutput, tt.expectedOutput) {
112-
t.Errorf("Output mismatch.\nExpected to contain:\n%s\nGot:\n%s", tt.expectedOutput, output)
115+
// Logging expected vs actual
116+
t.Logf("Expected Output:\n%s", tt.expectedOutput)
117+
t.Logf("Actual Output:\n%s", cleanOutput)
118+
119+
// Assertions
120+
assert.Equal(t, tt.expectedOutput, cleanOutput, "Output should match expected")
121+
if tt.expectedError {
122+
assert.Equal(t, 1, exitCode, "Expected exit code 1 on error")
123+
} else {
124+
assert.Equal(t, 0, exitCode, "Expected no exit (code 0) on success")
113125
}
114126
})
115127
}

cmd/pokemon.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ func PokemonCommand() {
5757

5858
flag.Parse()
5959

60+
if len(os.Args) == 3 && (os.Args[2] == "-h" || os.Args[2] == "--help") {
61+
flag.Usage()
62+
return
63+
}
64+
6065
err := ValidatePokemonArgs(args)
6166
if err != nil {
6267
fmt.Println(err.Error())

0 commit comments

Comments
 (0)