Skip to content

Commit 2dd8400

Browse files
Merge pull request #77 from digitalghost-dev/0.8.0
0.8.0
2 parents c43408c + 019710c commit 2dd8400

File tree

12 files changed

+276
-93
lines changed

12 files changed

+276
-93
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ on:
2222
branches:
2323
- main
2424
env:
25-
VERSION_NUMBER: 'v0.7.2'
25+
VERSION_NUMBER: 'v0.8.0'
2626
REGISTRY_NAME: digitalghostdev/poke-cli
2727

2828
jobs:

README.md

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +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.7.2?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.8.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>
8-
98
<div align="center">
109
<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">
1110
<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">
12-
11+
1312
</div>
1413

1514
## Overview
@@ -20,7 +19,7 @@ My aim is to have four commands finished for `v1.0.0`. Read more in the [Roadmap
2019

2120
---
2221
## Demo
23-
![demo](https://pokemon-objects.nyc3.digitaloceanspaces.com/demo_0.7.2.gif)
22+
![demo](https://pokemon-objects.nyc3.digitaloceanspaces.com/demo-v0.8.0.gif)
2423

2524
---
2625
## Install
@@ -35,7 +34,19 @@ _Download a pre-built binary_
3534
5. Either change directories into the extracted folder or move the binary to a chosen directory.
3635
6. Run the tool!
3736

38-
* Example usage:
37+
> [!IMPORTANT]
38+
> For macOS, you may have to allow the executable to run as it is not signed. Head to System Settings > Privacy & Security > scroll down and allow executable to run.
39+
40+
<details>
41+
42+
<summary>View Image of Settings</summary>
43+
44+
![settings](https://pokemon-objects.nyc3.digitaloceanspaces.com/macos_settings.png)
45+
46+
</details>
47+
48+
49+
#### Example usage
3950
```bash
4051
# Windows
4152
.\poke-cli.exe pokemon charizard --types --abilities
@@ -57,7 +68,7 @@ _Use a Docker Image_
5768
* Necessary.
5869

5970
```bash
60-
docker run --rm -i -t digitalghostdev/poke-cli:v0.7.2 <command> [subcommand] flag]
71+
docker run --rm -i -t digitalghostdev/poke-cli:v0.8.0 <command> [subcommand] flag]
6172
```
6273

6374
### Go Install
@@ -103,11 +114,10 @@ The architecture behind how the tool works is straight forward.
103114
_Not 100% up-to-date, may add or remove some of these choices_
104115

105116
- [ ] `pokemon`: get data about a specific Pokémon.
106-
- [x] `--abilities | -a`: display the Pokémon's abilities.
107-
- [x] `--types | -t`: display the Pokémon's typing.
108-
- [ ] `--stats | -s`: display the Pokémon's base stats.
109-
- [ ] `--metrics | -m`: display the Pokémon's metrics. (height, weight, etc.)
110-
- [ ] `types`: get data about a specific typing.
111-
- [ ] `--chart | -c`: display the type's damage chart. Undecided.
117+
- [x] `-a | --abilities`: display the Pokémon's abilities.
118+
- [x] `-s | --stats`: display the Pokémon's base stats.
119+
- [x] `-t | --types`: display the Pokémon's typing.
120+
- [ ] `-m | --moves`: display learnable moves.
121+
- [x] `types`: get data about a specific typing.
112122
- [ ] `ability`: get data about a specific ability.
113-
- [ ] `moves`: get data about a specific move.
123+
- [ ] `move`: get data about a specific move.

cli_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func TestRunCLI(t *testing.T) {
110110
{
111111
name: "Latest Flag",
112112
args: []string{"-l"},
113-
expectedOutput: "Latest Docker image version: v0.7.1\nLatest release tag: v0.7.1\n",
113+
expectedOutput: "Latest Docker image version: v0.7.2\nLatest release tag: v0.7.2\n",
114114
expectedCode: 0,
115115
},
116116
}

cmd/pokemon.go

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/digitalghost-dev/poke-cli/flags"
88
"golang.org/x/text/cases"
99
"golang.org/x/text/language"
10+
"math"
1011
"os"
1112
"strings"
1213
)
@@ -22,16 +23,17 @@ func PokemonCommand() {
2223
fmt.Sprintf("\n\t%-30s", styleItalic.Render("Use a hyphen when typing a name with a space.")),
2324
"\n\n",
2425
styleBold.Render("FLAGS:"),
25-
fmt.Sprintf("\n\t%-30s %s", "-a, --abilities", "Prints out the Pokémon's abilities."),
26-
fmt.Sprintf("\n\t%-30s %s", "-t, --types", "Prints out the Pokémon's typing."),
27-
fmt.Sprintf("\n\t%-30s %s", "-h, --help", "Prints out the help menu."),
26+
fmt.Sprintf("\n\t%-30s %s", "-a, --abilities", "Prints the Pokémon's abilities."),
27+
fmt.Sprintf("\n\t%-30s %s", "-s, --stats", "Prints the Pokémon's base stats."),
28+
fmt.Sprintf("\n\t%-30s %s", "-t, --types", "Prints the Pokémon's typing."),
29+
fmt.Sprintf("\n\t%-30s %s", "-h, --help", "Prints the help menu."),
2830
)
2931
fmt.Println(helpMessage)
3032
}
3133

3234
flag.Parse()
3335

34-
pokeFlags, typesFlag, shortTypesFlag, abilitiesFlag, shortAbilitiesFlag := flags.SetupPokemonFlagSet()
36+
pokeFlags, abilitiesFlag, shortAbilitiesFlag, statsFlag, shortStatsFlag, typesFlag, shortTypesFlag := flags.SetupPokemonFlagSet()
3537

3638
args := os.Args
3739

@@ -50,10 +52,36 @@ func PokemonCommand() {
5052
os.Exit(1)
5153
}
5254

53-
_, pokemonName, pokemonID := connections.PokemonApiCall(endpoint, pokemonName, "https://pokeapi.co/api/v2/")
55+
_, pokemonName, pokemonID, pokemonWeight, pokemonHeight := connections.PokemonApiCall(endpoint, pokemonName, "https://pokeapi.co/api/v2/")
5456
capitalizedString := cases.Title(language.English).String(pokemonName)
5557

56-
fmt.Printf("Your selected Pokémon: %s\nNational Pokédex #: %d\n", capitalizedString, pokemonID)
58+
// Weight calculation
59+
weightKilograms := float64(pokemonWeight) / 10
60+
weightPounds := float64(weightKilograms) * 2.20462
61+
62+
// Height calculation
63+
heightMeters := float64(pokemonHeight) / 10
64+
heightFeet := heightMeters * 3.28084
65+
feet := int(heightFeet)
66+
inches := int(math.Round((heightFeet - float64(feet)) * 12)) // Use math.Round to avoid truncation
67+
68+
// Adjust for rounding to 12 inches (carry over to the next foot)
69+
if inches == 12 {
70+
feet++
71+
inches = 0
72+
}
73+
74+
fmt.Printf(
75+
"Your selected Pokémon: %s\nNational Pokédex #: %d\nWeight: %.1fkg (%.1f lbs)\nHeight: %.1fm (%d′%02d″)\n",
76+
capitalizedString, pokemonID, weightKilograms, weightPounds, heightFeet, feet, inches,
77+
)
78+
79+
if *abilitiesFlag || *shortAbilitiesFlag {
80+
if err := flags.AbilitiesFlag(endpoint, pokemonName); err != nil {
81+
fmt.Printf("Error: %s\n", err)
82+
os.Exit(1)
83+
}
84+
}
5785

5886
if *typesFlag || *shortTypesFlag {
5987
if err := flags.TypesFlag(endpoint, pokemonName); err != nil {
@@ -62,8 +90,8 @@ func PokemonCommand() {
6290
}
6391
}
6492

65-
if *abilitiesFlag || *shortAbilitiesFlag {
66-
if err := flags.AbilitiesFlag(endpoint, pokemonName); err != nil {
93+
if *statsFlag || *shortStatsFlag {
94+
if err := flags.StatsFlag(endpoint, pokemonName); err != nil {
6795
fmt.Printf("Error: %s\n", err)
6896
os.Exit(1)
6997
}

cmd/pokemon_test.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,6 @@ func TestPokemonCommand(t *testing.T) {
7676
t.Fatalf("Failed to read from pipe: %v", readErr)
7777
}
7878

79-
// Define expected output based on actual API response
80-
expectedName := "Bulbasaur"
81-
expectedID := "1"
82-
8379
// Assert output contains expected Pokémon details
84-
assert.Contains(t, output.String(), "Your selected Pokémon:", "Output should contain Pokémon details header")
85-
assert.Contains(t, output.String(), expectedName, "Output should contain the Pokémon name")
86-
assert.Contains(t, output.String(), "National Pokédex #:", "Output should contain Pokémon ID header")
87-
assert.Contains(t, output.String(), expectedID, "Output should contain the Pokémon ID")
80+
assert.Equal(t, output.String(), "Your selected Pokémon: Bulbasaur\nNational Pokédex #: 1\nWeight: 6.9kg (15.2 lbs)\nHeight: 2.3m (2′04″)\n")
8881
}

cmd/validateargs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func ValidatePokemonArgs(args []string) error {
3131
return fmt.Errorf("%s", errMessage)
3232
}
3333

34-
if len(args) > 5 {
34+
if len(args) > 6 {
3535
errMessage := errorBorder.Render(errorColor.Render("Error!"), "\nToo many arguments")
3636
return fmt.Errorf("%s", errMessage)
3737
}

connections/connection.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,10 @@ import (
1111
)
1212

1313
type PokemonJSONStruct struct {
14-
Name string `json:"name"`
15-
ID int `json:"id"`
16-
Types []struct {
17-
Slot int `json:"slot"`
18-
Type struct {
19-
Name string `json:"name"`
20-
URL string `json:"url"`
21-
} `json:"type"`
22-
} `json:"types"`
14+
Name string `json:"name"`
15+
ID int `json:"id"`
16+
Weight int `json:"weight"`
17+
Height int `json:"height"`
2318
Abilities []struct {
2419
Ability struct {
2520
Name string `json:"name"`
@@ -28,6 +23,19 @@ type PokemonJSONStruct struct {
2823
Hidden bool `json:"hidden"`
2924
Slot int `json:"slot"`
3025
} `json:"abilities"`
26+
Types []struct {
27+
Slot int `json:"slot"`
28+
Type struct {
29+
Name string `json:"name"`
30+
URL string `json:"url"`
31+
} `json:"type"`
32+
} `json:"types"`
33+
Stats []struct {
34+
BaseStat int `json:"base_stat"`
35+
Stat struct {
36+
Name string `json:"name"`
37+
} `json:"stat"`
38+
} `json:"stats"`
3139
}
3240

3341
type TypesJSONStruct struct {
@@ -102,17 +110,17 @@ func ApiCallSetup(url string, target interface{}) error {
102110
return nil
103111
}
104112

105-
func PokemonApiCall(endpoint string, pokemonName string, baseURL string) (PokemonJSONStruct, string, int) {
113+
func PokemonApiCall(endpoint string, pokemonName string, baseURL string) (PokemonJSONStruct, string, int, int, int) {
106114

107115
url := baseURL + endpoint + "/" + pokemonName
108116
var pokemonStruct PokemonJSONStruct
109117

110118
err := ApiCallSetup(url, &pokemonStruct)
111119
if err != nil {
112-
return PokemonJSONStruct{}, "", 0
120+
return PokemonJSONStruct{}, "", 0, 0, 0
113121
}
114122

115-
return pokemonStruct, pokemonStruct.Name, pokemonStruct.ID
123+
return pokemonStruct, pokemonStruct.Name, pokemonStruct.ID, pokemonStruct.Weight, pokemonStruct.Height
116124
}
117125

118126
func TypesApiCall(endpoint string, typesName string, baseURL string) (TypesJSONStruct, string, int) {

connections/connection_test.go

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

12-
// TestBaseApiCallSuccess - Test for the ApiCallSetup function
13-
func TestBaseApiCallSuccess(t *testing.T) {
12+
// TestBaseApiCall - Test for the ApiCallSetup function
13+
func TestBaseApiCall(t *testing.T) {
1414
expectedData := map[string]string{"key": "value"}
1515

1616
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -30,11 +30,13 @@ func TestBaseApiCallSuccess(t *testing.T) {
3030
assert.Equal(t, expectedData, target)
3131
}
3232

33-
// TestPokemonApiCallSuccess - Test for the PokemonApiCall function
34-
func TestPokemonApiCallSuccess(t *testing.T) {
33+
// TestPokemonApiCall - Test for the PokemonApiCall function
34+
func TestPokemonApiCall(t *testing.T) {
3535
expectedPokemon := PokemonJSONStruct{
36-
Name: "pikachu",
37-
ID: 25,
36+
Name: "pikachu",
37+
ID: 25,
38+
Weight: 60,
39+
Height: 4,
3840
Types: []struct {
3941
Slot int `json:"slot"`
4042
Type struct {
@@ -56,15 +58,17 @@ func TestPokemonApiCallSuccess(t *testing.T) {
5658
}))
5759
defer ts.Close()
5860

59-
pokemon, name, id := PokemonApiCall("/pokemon", "pikachu", ts.URL)
61+
pokemon, name, id, weight, height := PokemonApiCall("/pokemon", "pikachu", ts.URL)
6062

6163
assert.Equal(t, expectedPokemon, pokemon)
6264
assert.Equal(t, "pikachu", name)
6365
assert.Equal(t, 25, id)
66+
assert.Equal(t, 60, weight)
67+
assert.Equal(t, 4, height)
6468
}
6569

66-
// TestTypesApiCallSuccess - Test for the TypesApiCall function
67-
func TestTypesApiCallSuccess(t *testing.T) {
70+
// TestTypesApiCall - Test for the TypesApiCall function
71+
func TestTypesApiCall(t *testing.T) {
6872
expectedTypes := TypesJSONStruct{
6973
Name: "electric",
7074
ID: 13,

demo.gif

66.6 KB
Loading

demo.tape

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ Require echo
6262
Set Shell "bash"
6363
Set FontSize 32
6464
Set Width 2100
65-
Set Height 825
65+
Set Height 1100
6666

67-
Type "poke-cli pokemon charizard --types --abilities"
67+
Type "poke-cli pokemon charizard --abilities --stats --types"
6868

6969
Sleep 1s
7070

0 commit comments

Comments
 (0)