Skip to content

Commit

Permalink
Merge pull request #77 from digitalghost-dev/0.8.0
Browse files Browse the repository at this point in the history
0.8.0
  • Loading branch information
digitalghost-dev authored Nov 27, 2024
2 parents c43408c + 019710c commit 2dd8400
Show file tree
Hide file tree
Showing 12 changed files with 276 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ on:
branches:
- main
env:
VERSION_NUMBER: 'v0.7.2'
VERSION_NUMBER: 'v0.8.0'
REGISTRY_NAME: digitalghostdev/poke-cli

jobs:
Expand Down
36 changes: 23 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
<img height="250" width="350" src="https://cdn.simpleicons.org/pokemon/FFCC00" 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/v0.7.2?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/v0.8.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">
<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">
<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">

</div>

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

---
## Demo
![demo](https://pokemon-objects.nyc3.digitaloceanspaces.com/demo_0.7.2.gif)
![demo](https://pokemon-objects.nyc3.digitaloceanspaces.com/demo-v0.8.0.gif)

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

* Example usage:
> [!IMPORTANT]
> 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.
<details>

<summary>View Image of Settings</summary>

![settings](https://pokemon-objects.nyc3.digitaloceanspaces.com/macos_settings.png)

</details>


#### Example usage
```bash
# Windows
.\poke-cli.exe pokemon charizard --types --abilities
Expand All @@ -57,7 +68,7 @@ _Use a Docker Image_
* Necessary.

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

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

- [ ] `pokemon`: get data about a specific Pokémon.
- [x] `--abilities | -a`: display the Pokémon's abilities.
- [x] `--types | -t`: display the Pokémon's typing.
- [ ] `--stats | -s`: display the Pokémon's base stats.
- [ ] `--metrics | -m`: display the Pokémon's metrics. (height, weight, etc.)
- [ ] `types`: get data about a specific typing.
- [ ] `--chart | -c`: display the type's damage chart. Undecided.
- [x] `-a | --abilities`: display the Pokémon's abilities.
- [x] `-s | --stats`: display the Pokémon's base stats.
- [x] `-t | --types`: display the Pokémon's typing.
- [ ] `-m | --moves`: display learnable moves.
- [x] `types`: get data about a specific typing.
- [ ] `ability`: get data about a specific ability.
- [ ] `moves`: get data about a specific move.
- [ ] `move`: get data about a specific move.
2 changes: 1 addition & 1 deletion cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestRunCLI(t *testing.T) {
{
name: "Latest Flag",
args: []string{"-l"},
expectedOutput: "Latest Docker image version: v0.7.1\nLatest release tag: v0.7.1\n",
expectedOutput: "Latest Docker image version: v0.7.2\nLatest release tag: v0.7.2\n",
expectedCode: 0,
},
}
Expand Down
44 changes: 36 additions & 8 deletions cmd/pokemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/digitalghost-dev/poke-cli/flags"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"math"
"os"
"strings"
)
Expand All @@ -22,16 +23,17 @@ func PokemonCommand() {
fmt.Sprintf("\n\t%-30s", styleItalic.Render("Use a hyphen when typing a name with a space.")),
"\n\n",
styleBold.Render("FLAGS:"),
fmt.Sprintf("\n\t%-30s %s", "-a, --abilities", "Prints out the Pokémon's abilities."),
fmt.Sprintf("\n\t%-30s %s", "-t, --types", "Prints out the Pokémon's typing."),
fmt.Sprintf("\n\t%-30s %s", "-h, --help", "Prints out the help menu."),
fmt.Sprintf("\n\t%-30s %s", "-a, --abilities", "Prints the Pokémon's abilities."),
fmt.Sprintf("\n\t%-30s %s", "-s, --stats", "Prints the Pokémon's base stats."),
fmt.Sprintf("\n\t%-30s %s", "-t, --types", "Prints the Pokémon's typing."),
fmt.Sprintf("\n\t%-30s %s", "-h, --help", "Prints the help menu."),
)
fmt.Println(helpMessage)
}

flag.Parse()

pokeFlags, typesFlag, shortTypesFlag, abilitiesFlag, shortAbilitiesFlag := flags.SetupPokemonFlagSet()
pokeFlags, abilitiesFlag, shortAbilitiesFlag, statsFlag, shortStatsFlag, typesFlag, shortTypesFlag := flags.SetupPokemonFlagSet()

args := os.Args

Expand All @@ -50,10 +52,36 @@ func PokemonCommand() {
os.Exit(1)
}

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

fmt.Printf("Your selected Pokémon: %s\nNational Pokédex #: %d\n", capitalizedString, pokemonID)
// Weight calculation
weightKilograms := float64(pokemonWeight) / 10
weightPounds := float64(weightKilograms) * 2.20462

// Height calculation
heightMeters := float64(pokemonHeight) / 10
heightFeet := heightMeters * 3.28084
feet := int(heightFeet)
inches := int(math.Round((heightFeet - float64(feet)) * 12)) // Use math.Round to avoid truncation

// Adjust for rounding to 12 inches (carry over to the next foot)
if inches == 12 {
feet++
inches = 0
}

fmt.Printf(
"Your selected Pokémon: %s\nNational Pokédex #: %d\nWeight: %.1fkg (%.1f lbs)\nHeight: %.1fm (%d′%02d″)\n",
capitalizedString, pokemonID, weightKilograms, weightPounds, heightFeet, feet, inches,
)

if *abilitiesFlag || *shortAbilitiesFlag {
if err := flags.AbilitiesFlag(endpoint, pokemonName); err != nil {
fmt.Printf("Error: %s\n", err)
os.Exit(1)
}
}

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

if *abilitiesFlag || *shortAbilitiesFlag {
if err := flags.AbilitiesFlag(endpoint, pokemonName); err != nil {
if *statsFlag || *shortStatsFlag {
if err := flags.StatsFlag(endpoint, pokemonName); err != nil {
fmt.Printf("Error: %s\n", err)
os.Exit(1)
}
Expand Down
9 changes: 1 addition & 8 deletions cmd/pokemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@ func TestPokemonCommand(t *testing.T) {
t.Fatalf("Failed to read from pipe: %v", readErr)
}

// Define expected output based on actual API response
expectedName := "Bulbasaur"
expectedID := "1"

// Assert output contains expected Pokémon details
assert.Contains(t, output.String(), "Your selected Pokémon:", "Output should contain Pokémon details header")
assert.Contains(t, output.String(), expectedName, "Output should contain the Pokémon name")
assert.Contains(t, output.String(), "National Pokédex #:", "Output should contain Pokémon ID header")
assert.Contains(t, output.String(), expectedID, "Output should contain the Pokémon ID")
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")
}
2 changes: 1 addition & 1 deletion cmd/validateargs.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func ValidatePokemonArgs(args []string) error {
return fmt.Errorf("%s", errMessage)
}

if len(args) > 5 {
if len(args) > 6 {
errMessage := errorBorder.Render(errorColor.Render("Error!"), "\nToo many arguments")
return fmt.Errorf("%s", errMessage)
}
Expand Down
32 changes: 20 additions & 12 deletions connections/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@ import (
)

type PokemonJSONStruct struct {
Name string `json:"name"`
ID int `json:"id"`
Types []struct {
Slot int `json:"slot"`
Type struct {
Name string `json:"name"`
URL string `json:"url"`
} `json:"type"`
} `json:"types"`
Name string `json:"name"`
ID int `json:"id"`
Weight int `json:"weight"`
Height int `json:"height"`
Abilities []struct {
Ability struct {
Name string `json:"name"`
Expand All @@ -28,6 +23,19 @@ type PokemonJSONStruct struct {
Hidden bool `json:"hidden"`
Slot int `json:"slot"`
} `json:"abilities"`
Types []struct {
Slot int `json:"slot"`
Type struct {
Name string `json:"name"`
URL string `json:"url"`
} `json:"type"`
} `json:"types"`
Stats []struct {
BaseStat int `json:"base_stat"`
Stat struct {
Name string `json:"name"`
} `json:"stat"`
} `json:"stats"`
}

type TypesJSONStruct struct {
Expand Down Expand Up @@ -102,17 +110,17 @@ func ApiCallSetup(url string, target interface{}) error {
return nil
}

func PokemonApiCall(endpoint string, pokemonName string, baseURL string) (PokemonJSONStruct, string, int) {
func PokemonApiCall(endpoint string, pokemonName string, baseURL string) (PokemonJSONStruct, string, int, int, int) {

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

err := ApiCallSetup(url, &pokemonStruct)
if err != nil {
return PokemonJSONStruct{}, "", 0
return PokemonJSONStruct{}, "", 0, 0, 0
}

return pokemonStruct, pokemonStruct.Name, pokemonStruct.ID
return pokemonStruct, pokemonStruct.Name, pokemonStruct.ID, pokemonStruct.Weight, pokemonStruct.Height
}

func TypesApiCall(endpoint string, typesName string, baseURL string) (TypesJSONStruct, string, int) {
Expand Down
22 changes: 13 additions & 9 deletions connections/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"testing"
)

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

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

// TestPokemonApiCallSuccess - Test for the PokemonApiCall function
func TestPokemonApiCallSuccess(t *testing.T) {
// TestPokemonApiCall - Test for the PokemonApiCall function
func TestPokemonApiCall(t *testing.T) {
expectedPokemon := PokemonJSONStruct{
Name: "pikachu",
ID: 25,
Name: "pikachu",
ID: 25,
Weight: 60,
Height: 4,
Types: []struct {
Slot int `json:"slot"`
Type struct {
Expand All @@ -56,15 +58,17 @@ func TestPokemonApiCallSuccess(t *testing.T) {
}))
defer ts.Close()

pokemon, name, id := PokemonApiCall("/pokemon", "pikachu", ts.URL)
pokemon, name, id, weight, height := PokemonApiCall("/pokemon", "pikachu", ts.URL)

assert.Equal(t, expectedPokemon, pokemon)
assert.Equal(t, "pikachu", name)
assert.Equal(t, 25, id)
assert.Equal(t, 60, weight)
assert.Equal(t, 4, height)
}

// TestTypesApiCallSuccess - Test for the TypesApiCall function
func TestTypesApiCallSuccess(t *testing.T) {
// TestTypesApiCall - Test for the TypesApiCall function
func TestTypesApiCall(t *testing.T) {
expectedTypes := TypesJSONStruct{
Name: "electric",
ID: 13,
Expand Down
Binary file modified demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions demo.tape
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ Require echo
Set Shell "bash"
Set FontSize 32
Set Width 2100
Set Height 825
Set Height 1100

Type "poke-cli pokemon charizard --types --abilities"
Type "poke-cli pokemon charizard --abilities --stats --types"

Sleep 1s

Expand Down
Loading

0 comments on commit 2dd8400

Please sign in to comment.