Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.6.1 #46

Closed
wants to merge 4 commits into from
Closed
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 @@ -11,7 +11,7 @@ on:
branches:
- main
env:
VERSION_NUMBER: 'v0.6.0'
VERSION_NUMBER: 'v0.6.1'
REGISTRY_NAME: digitalghostdev/poke-cli

jobs:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<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.6.0?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.6.1?arch=arm64&style=flat-square&logo=docker&logoColor=FFCC00&labelColor=EEE&color=FFCC00" alt="docker-image-size">
</div>

<div align="center">
Expand Down
29 changes: 20 additions & 9 deletions cmd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ func (m model) View() string {
return "Select a type! Hit 'Q' or 'CTRL-C' to quit.\n" + baseStyle.Render(m.table.View()) + "\n"
}

func selectionResult(endpoint, typesName string) error {
baseURL := "https://pokeapi.co/api/v2/"

typeResponse, typeName, _ := connections.TypesApiCall(endpoint, typesName, baseURL)

capitalizedString := cases.Title(language.English).String(typeName)

pokemonCount := len(typeResponse.Pokemon)

fmt.Printf("You selected Type: %s\nNumber of Pokémon with type: %d\n", capitalizedString, pokemonCount)
return nil
}

func TypesCommand() {
flag.Usage = func() {
helpMessage := helpBorder.Render(
Expand Down Expand Up @@ -123,8 +136,6 @@ func TypesCommand() {
t.SetStyles(s)

m := model{table: t}

// Run the program and capture the final state
programModel, err := tea.NewProgram(m).Run()
if err != nil {
fmt.Println("Error running program:", err)
Expand All @@ -133,14 +144,14 @@ func TypesCommand() {

// Type assert to model and access the selected option
finalModel := programModel.(model)

endpoint := strings.ToLower(args[1])[0:4]
typesName := strings.ToLower(finalModel.selectedOption)

typeResponse, typeName, _ := connections.TypesApiCall(endpoint, typesName, "https://pokeapi.co/api/v2/")
capitalizedString := cases.Title(language.English).String(typeName)

pokemonCount := len(typeResponse.Pokemon)
// Extract the first 4 characters of the endpoint from the argument
endpoint := strings.ToLower(args[1])[0:4]

fmt.Printf("You selected Type: %s\nNumber of Pokémon with type: %d\n", capitalizedString, pokemonCount)
// Call the selectionTable function with the selected type and endpoint
if err := selectionResult(endpoint, typesName); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
}
13 changes: 13 additions & 0 deletions cmd/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,16 @@ func TestValidateTypesArgs_ValidInput(t *testing.T) {
assert.NoError(t, err, "Expected no error for valid input")
}
}

func TestValidateTypesArgs_TooManyArgs(t *testing.T) {
invalidInputs := [][]string{
{"poke-cli", "types", "ground"},
}
expectedError := "error, too many arguemnts\n"

for _, input := range invalidInputs {
err := ValidateTypesArgs(input)
assert.Error(t, err, "Expected error for too many arguments")
assert.NotEqual(t, expectedError, err.Error())
}
}
16 changes: 10 additions & 6 deletions cmd/validateargs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import (
func ValidatePokemonArgs(args []string) error {

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

if len(args) < 3 {
return fmt.Errorf(errorBorder.Render(errorColor.Render("Error!"), "\nPlease declare a Pokémon's name after the [pokemon] command", "\nRun 'poke-cli pokemon -h' for more details", "\nerror: insufficient arguments"))
errMessage := errorBorder.Render(errorColor.Render("Error!"), "\nPlease declare a Pokémon's name after the [pokemon] command", "\nRun 'poke-cli pokemon -h' for more details", "\nerror: insufficient arguments")
return fmt.Errorf("%s", errMessage)
}

if len(args) > 3 {
Expand All @@ -22,7 +24,8 @@ func ValidatePokemonArgs(args []string) error {
errorTitle := errorColor.Render("Error!")
errorString := fmt.Sprintf("\nInvalid argument '%s'. Only flags are allowed after declaring a Pokémon's name", arg)
formattedString := errorTitle + errorString
return fmt.Errorf(errorBorder.Render(formattedString))
renderedError := errorBorder.Render(formattedString)
return fmt.Errorf("%s", renderedError)
}
}
}
Expand All @@ -38,12 +41,13 @@ func ValidatePokemonArgs(args []string) error {
// ValidateTypesArgs validates the command line arguments
func ValidateTypesArgs(args []string) error {
if len(args) > 3 {
return fmt.Errorf(errorBorder.Render(errorColor.Render("Error!"), "\nToo many arguments"))
errMessage := errorBorder.Render(errorColor.Render("Error!"), "\nToo many arguments")
return fmt.Errorf("%s", errMessage)
}

if len(args) == 3 && (args[2] != "-h" && args[2] != "--help") {
fmt.Println(errorBorder.Render("Error! The only currently available options\nafter [types] command is '-h' or '--help'"))
return nil
errMessage := errorBorder.Render("Error! The only currently available options\nafter [types] command is '-h' or '--help'")
return fmt.Errorf("%s", errMessage)
}

return nil
Expand Down
Loading