Skip to content

Commit 7957cfe

Browse files
Merge pull request #86 from digitalghost-dev/0.9.2
0.9.2
2 parents 1413337 + db1ec6e commit 7957cfe

File tree

7 files changed

+165
-35
lines changed

7 files changed

+165
-35
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ on:
2323
- '.goreleaser.yaml'
2424
branches:
2525
- main
26+
2627
env:
27-
VERSION_NUMBER: 'v0.9.1'
28+
VERSION_NUMBER: 'v0.9.2'
2829
DOCKERHUB_REGISTRY_NAME: 'digitalghostdev/poke-cli'
2930
AWS_REGION: 'us-west-2'
3031

README.md

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
<img height="250" width="350" src="https://cdn.simpleicons.org/pokemon/FFCC00" 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/v0.9.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/v0.9.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">
99
<img src="https://img.shields.io/github/actions/workflow/status/digitalghost-dev/poke-cli/go_test.yml?style=flat-square&logo=go&logoColor=00ADD8&label=Tests&labelColor=EEE&color=00ADD8" alt="tests-label">
10-
<img src="https://img.shields.io/github/go-mod/go-version/digitalghost-dev/poke-cli?style=flat-square&logo=Go&labelColor=EEE&color=00ADD8" alt="go-version">
11-
10+
<img src="https://img.shields.io/github/go-mod/go-version/digitalghost-dev/poke-cli?style=flat-square&logo=Go&labelColor=EEE&color=00ADD8" alt="go-version"/>
11+
<img src="https://img.shields.io/codecov/c/github/digitalghost-dev/poke-cli?token=05GBSAOQIT&style=flat-square&logo=codecov&logoColor=00ADD8&labelColor=EEE&color=00ADD8" alt="codecov"/>
1212
</div>
1313

1414
## Overview
@@ -68,7 +68,7 @@ _Use a Docker Image_
6868
* Necessary.
6969

7070
```bash
71-
docker run --rm -i -t digitalghostdev/poke-cli:v0.9.1 <command> [subcommand] flag]
71+
docker run --rm -i -t digitalghostdev/poke-cli:v0.9.2 <command> [subcommand] flag]
7272
```
7373

7474
### Go Install
@@ -83,23 +83,23 @@ _If you have Go already, install the executable yourself_
8383
## Usage
8484
By running `poke-cli [-h | --help]`, it'll display information on how to use the tool.
8585
```
86-
╭──────────────────────────────────────────────────────╮
87-
│Welcome! This tool displays data related to Pokémon! │
88-
│ │
89-
│ USAGE: │
90-
│ poke-cli [flag] │
91-
│ poke-cli <command> [flag] │
92-
│ poke-cli <command> <subcommand> [flag] │
93-
│ │
94-
│ FLAGS: │
95-
│ -h, --help Shows the help menu │
96-
│ -l, --latest Prints the latest available
97-
version of the program
98-
│ │
99-
│ AVAILABLE COMMANDS: │
100-
│ pokemon Get details of a specific Pokémon │
101-
│ types Get details of a specific typing │
102-
╰──────────────────────────────────────────────────────╯
86+
╭────────────────────────────────────────────────────────
87+
│Welcome! This tool displays data related to Pokémon!
88+
89+
│ USAGE:
90+
│ poke-cli [flag]
91+
│ poke-cli <command> [flag]
92+
│ poke-cli <command> <subcommand> [flag]
93+
94+
│ FLAGS:
95+
│ -h, --help Shows the help menu
96+
│ -l, --latest Prints the latest version available
97+
-v, --version Prints the current version
98+
99+
│ AVAILABLE COMMANDS:
100+
│ pokemon Get details of a specific Pokémon
101+
│ types Get details of a specific typing
102+
╰────────────────────────────────────────────────────────
103103
```
104104

105105
---
@@ -119,4 +119,6 @@ _Not 100% up-to-date, may add or remove some of these choices_
119119
- [ ] `-m | --moves`: display learnable moves.
120120
- [x] `types`: get data about a specific typing.
121121
- [ ] `ability`: get data about a specific ability.
122-
- [ ] `move`: get data about a specific move.
122+
- [ ] `-p | --pokemon`: display Pokémon that learn this ability.
123+
- [ ] `move`: get data about a specific move.
124+
- [ ] `-p | --pokemon`: display Pokémon that learn this move.

cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func runCLI(args []string) int {
5151
latestFlag := mainFlagSet.Bool("latest", false, "Prints the program's latest Docker image and release versions.")
5252
shortLatestFlag := mainFlagSet.Bool("l", false, "Prints the program's latest Docker image and release versions.")
5353

54-
// -v, --version flag retrives the currently installed version
54+
// -v, --version flag retrieves the currently installed version
5555
currentVersionFlag := mainFlagSet.Bool("version", false, "Prints the current version")
5656
shortCurrentVersionFlag := mainFlagSet.Bool("v", false, "Prints the current version")
5757

cli_test.go

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,63 @@ import (
77
"testing"
88
)
99

10+
func TestCurrentVersion(t *testing.T) {
11+
tests := []struct {
12+
name string
13+
version string
14+
expectedOutput string
15+
}{
16+
{
17+
name: "Version set by ldflags",
18+
version: "v1.0.0",
19+
expectedOutput: "Version: v1.0.0\n",
20+
},
21+
{
22+
name: "Version set to (devel)",
23+
version: "(devel)",
24+
expectedOutput: "Version: (devel)\n", // Simplified assumption
25+
},
26+
}
27+
28+
// Save the original version and restore it after tests
29+
originalVersion := version
30+
defer func() { version = originalVersion }()
31+
32+
for _, tt := range tests {
33+
t.Run(tt.name, func(t *testing.T) {
34+
// Set the version for this test case
35+
version = tt.version
36+
37+
// Redirect stdout to capture the output
38+
r, w, _ := os.Pipe()
39+
oldStdout := os.Stdout
40+
os.Stdout = w
41+
42+
// Call the function
43+
currentVersion()
44+
45+
// Close the writer and restore stdout
46+
err := w.Close()
47+
if err != nil {
48+
t.Fatalf("Failed to close pipe: %v", err)
49+
}
50+
os.Stdout = oldStdout
51+
52+
// Read the output from the pipe
53+
var buf bytes.Buffer
54+
if _, err := buf.ReadFrom(r); err != nil {
55+
t.Fatalf("Failed to read from pipe: %v", err)
56+
}
57+
58+
// Compare the output with the expected result
59+
got := buf.String()
60+
if got != tt.expectedOutput {
61+
t.Errorf("Expected %q, got %q", tt.expectedOutput, got)
62+
}
63+
})
64+
}
65+
}
66+
1067
var ansiRegex = regexp.MustCompile(`\x1b\[[0-9;]*m`)
1168

1269
func captureOutput(f func()) string {
@@ -110,7 +167,7 @@ func TestRunCLI(t *testing.T) {
110167
{
111168
name: "Latest Flag",
112169
args: []string{"-l"},
113-
expectedOutput: "Latest Docker image version: v0.9.0\nLatest release tag: v0.9.0\n",
170+
expectedOutput: "Latest Docker image version: v0.9.1\nLatest release tag: v0.9.1\n",
114171
expectedCode: 0,
115172
},
116173
}
@@ -133,3 +190,44 @@ func TestRunCLI(t *testing.T) {
133190
})
134191
}
135192
}
193+
194+
func TestMainFunction(t *testing.T) {
195+
originalExit := exit
196+
defer func() { exit = originalExit }() // Restore original exit after test
197+
198+
tests := []struct {
199+
name string
200+
args []string
201+
expectedOutput string
202+
expectedCode int
203+
}{
204+
{
205+
name: "Run main command",
206+
args: []string{"poke-cli"},
207+
expectedOutput: "Welcome! This tool displays data related to Pokémon!",
208+
expectedCode: 0,
209+
},
210+
}
211+
212+
for _, tt := range tests {
213+
t.Run(tt.name, func(t *testing.T) {
214+
exitCode := 0
215+
exit = func(code int) { exitCode = code }
216+
217+
output := captureOutput(func() {
218+
os.Args = tt.args
219+
main()
220+
})
221+
222+
output = stripANSI(output)
223+
224+
if exitCode != tt.expectedCode {
225+
t.Errorf("Expected exit code %d, got %d", tt.expectedCode, exitCode)
226+
}
227+
228+
if !bytes.Contains([]byte(output), []byte(tt.expectedOutput)) {
229+
t.Errorf("Expected output to contain %q, got %q", tt.expectedOutput, output)
230+
}
231+
})
232+
}
233+
}

cmd/pokemon.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func PokemonCommand() {
5353
}
5454

5555
_, pokemonName, pokemonID, pokemonWeight, pokemonHeight := connections.PokemonApiCall(endpoint, pokemonName, "https://pokeapi.co/api/v2/")
56-
capitalizedString := cases.Title(language.English).String(pokemonName)
56+
capitalizedString := cases.Title(language.English).String(strings.Replace(pokemonName, "-", " ", -1))
5757

5858
// Weight calculation
5959
weightKilograms := float64(pokemonWeight) / 10

flags/pokemonflagset.go

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"fmt"
88
"github.com/charmbracelet/lipgloss"
99
"github.com/digitalghost-dev/poke-cli/connections"
10+
"golang.org/x/text/cases"
11+
"golang.org/x/text/language"
1012
"strings"
1113
)
1214

@@ -58,13 +60,38 @@ func AbilitiesFlag(endpoint string, pokemonName string) error {
5860

5961
header("Abilities")
6062

63+
// Anonymous function to format ability names
64+
formatAbilityName := func(name string) string {
65+
exceptions := map[string]bool{
66+
"of": true,
67+
"the": true,
68+
"to": true,
69+
"as": true,
70+
}
71+
72+
name = strings.Replace(name, "-", " ", -1)
73+
words := strings.Split(name, " ")
74+
titleCaser := cases.Title(language.English)
75+
76+
// Process each word
77+
for i, word := range words {
78+
if _, found := exceptions[strings.ToLower(word)]; found && i != 0 {
79+
words[i] = strings.ToLower(word)
80+
} else {
81+
words[i] = titleCaser.String(word)
82+
}
83+
}
84+
return strings.Join(words, " ")
85+
}
86+
6187
for _, pokeAbility := range pokemonStruct.Abilities {
88+
formattedName := formatAbilityName(pokeAbility.Ability.Name)
6289
if pokeAbility.Slot == 1 {
63-
fmt.Printf("Ability %d: %s\n", pokeAbility.Slot, pokeAbility.Ability.Name)
90+
fmt.Printf("Ability %d: %s\n", pokeAbility.Slot, formattedName)
6491
} else if pokeAbility.Slot == 2 {
65-
fmt.Printf("Ability %d: %s\n", pokeAbility.Slot, pokeAbility.Ability.Name)
92+
fmt.Printf("Ability %d: %s\n", pokeAbility.Slot, formattedName)
6693
} else {
67-
fmt.Printf("Hidden Ability: %s\n", pokeAbility.Ability.Name)
94+
fmt.Printf("Hidden Ability: %s\n", formattedName)
6895
}
6996
}
7097

@@ -181,9 +208,11 @@ func TypesFlag(endpoint string, pokemonName string) error {
181208
colorHex, exists := colorMap[pokeType.Type.Name]
182209
if exists {
183210
color := lipgloss.Color(colorHex)
184-
fmt.Printf("Type %d: %s\n", pokeType.Slot, lipgloss.NewStyle().Bold(true).Foreground(color).Render(pokeType.Type.Name))
211+
style := lipgloss.NewStyle().Bold(true).Foreground(color)
212+
styledName := style.Render(cases.Title(language.English).String(pokeType.Type.Name)) // Apply styling here
213+
fmt.Printf("Type %d: %s\n", pokeType.Slot, styledName) // Interpolate styled text
185214
} else {
186-
fmt.Printf("Type %d: %s\n", pokeType.Slot, pokeType.Type.Name)
215+
fmt.Printf("Type %d: %s\n", pokeType.Slot, cases.Title(language.English).String(pokeType.Type.Name))
187216
}
188217
}
189218

flags/pokemonflagset_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ func TestAbilitiesFlag(t *testing.T) {
7474
// Define the expected output based on the API response
7575
expectedOutput := `─────────
7676
Abilities
77-
Ability 1: overgrow
78-
Hidden Ability: chlorophyll
77+
Ability 1: Overgrow
78+
Hidden Ability: Chlorophyll
7979
`
8080

8181
// Assert the actual output matches the expected output
@@ -153,8 +153,8 @@ func TestTypesFlag(t *testing.T) {
153153
// Define expected output components
154154
expectedOutput := `──────
155155
Typing
156-
Type 1: grass
157-
Type 2: poison
156+
Type 1: Grass
157+
Type 2: Poison
158158
`
159159

160160
// Assert output contains the expected header and typing information

0 commit comments

Comments
 (0)