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\n National 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\n National Pokédex #: %d\n Weight: %.1fkg (%.1f lbs)\n Height: %.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 }
0 commit comments