Skip to content

Commit b836db0

Browse files
Merge pull request #70 from digitalghost-dev/0.7.1
0.7.1
2 parents c4175b0 + 9e75584 commit b836db0

File tree

13 files changed

+163
-57
lines changed

13 files changed

+163
-57
lines changed

.dccache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"/Users/cs/GolandProjects/poke-cli/cli.go":[2908,1731199451826.8408,"fe32be489436462dc7bec15aff72fdaf8718d161897cd0c301a8500784c38dc6"],"/Users/cs/GolandProjects/poke-cli/cli_test.go":[5660,1731346247797.8955,"dc62994b7701b8f48827fa6cac2e5cbe2bc4f3618b00f1529e187934120c79aa"],"/Users/cs/GolandProjects/poke-cli/cmd/pokemon.go":[2025,1731107596626.2603,"34a4ca4a4ce21dbfca8ce0351171114f19ead62579a7bce12710271ce2b43b44"],"/Users/cs/GolandProjects/poke-cli/cmd/pokemon_test.go":[1564,1727734768286.3376,"e5349582c85c7edfed1ffec5dc2d1fb117ec123feaec97cfbee60f20b4eb08ab"],"/Users/cs/GolandProjects/poke-cli/cmd/styles.go":[1244,1729983248031.173,"8acc71493eb32a0cd65e0aa748277fe2c0b18510f2617276101d6909b6a5f2f4"],"/Users/cs/GolandProjects/poke-cli/cmd/types.go":[6577,1731092007241.011,"4203101e899b7c0648042f23b945e7f2689283ed9b2305dfb363cec01b4e57de"],"/Users/cs/GolandProjects/poke-cli/cmd/types_test.go":[718,1729532136457.2212,"fbc72c3a5cf4b1b01c294808f68311a69faf4def91af15f894fd418727b16f5d"],"/Users/cs/GolandProjects/poke-cli/cmd/validateargs.go":[2060,1731111394011.11,"9abf89d6b055b7be3de7f231181d22438262208daa816f35bf39577b0d9692cc"],"/Users/cs/GolandProjects/poke-cli/cmd/validateargs_test.go":[1652,1728245306004.284,"7da0fd36b2bd7fd0e9bce0bafc13f6a9620fe25d2fa810418dffe42b190280a9"],"/Users/cs/GolandProjects/poke-cli/connections/connection.go":[3107,1731346514110.1143,"cd23b8f48bc30086c13fa393aa3584be03740afa8fa972e062e1a44995c26067"],"/Users/cs/GolandProjects/poke-cli/connections/connection_test.go":[4293,1731345803130.106,"108799e7030af4359726d919459545e33e23e0021388e3215b8d5707c482fbe0"],"/Users/cs/GolandProjects/poke-cli/flags/pokemonflagset.go":[3298,1730065034797.2764,"21a4a30afe40eb9cbd5fd12999debbb05c183adcd32452150c5b0e34b54b832e"],"/Users/cs/GolandProjects/poke-cli/flags/pokemonflagset_test.go":[1257,1730225862960.686,"6be704fd558c2cfdebf0261de3ecd478ba887f128d630ec762a9f53f03f3a842"],"/Users/cs/GolandProjects/poke-cli/flags/version.go":[1345,1731111344374.6135,"ef6a00218a6ed9c380c04e310c7970eff0e0b707198278730cb225ff4614636b"],"/Users/cs/GolandProjects/poke-cli/flags/version_test.go":[2474,1731346090382.8333,"4e641a4c3216bdaf4a6d5fed4f06bc5770b9d4aeb3d9b1ab34150950617bcfbf"]}

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ on:
2121
branches:
2222
- main
2323
env:
24-
VERSION_NUMBER: 'v0.7.0'
24+
VERSION_NUMBER: 'v0.7.1'
2525
REGISTRY_NAME: digitalghostdev/poke-cli
2626

2727
jobs:

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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.0?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.7.1?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">
77
</div>
88

@@ -16,7 +16,7 @@
1616
A CLI tool for viewing data about Pokémon from your terminal!
1717

1818
## Demo
19-
![demo](https://pokemon-objects.nyc3.digitaloceanspaces.com/demo.gif)
19+
![demo](https://pokemon-objects.nyc3.digitaloceanspaces.com/demo_0.7.1.gif)
2020

2121
## Install
2222

@@ -40,7 +40,7 @@ _Taskfile can build the executable for you_
4040
_Use a Docker Image_
4141

4242
```bash
43-
docker run --rm -it digitalghostdev/poke-cli:v0.7.0 [command] [subcommand] [flag]
43+
docker run --rm -it digitalghostdev/poke-cli:v0.7.1 [command] [subcommand] [flag]
4444
```
4545

4646
### Go Build
@@ -71,8 +71,8 @@ By running `poke-cli [-h | --help]`, it'll display information on how to use the
7171
│ │
7272
│ USAGE: │
7373
│ poke-cli [flag] │
74-
│ poke-cli [command] [flag] │
75-
│ poke-cli [command] [subcommand] [flag] │
74+
│ poke-cli <command> [flag] │
75+
│ poke-cli <command> <subcommand> [flag] │
7676
│ │
7777
│ FLAGS: │
7878
│ -h, --help Shows the help menu │

cli.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ func runCLI(args []string) int {
3030
"Welcome! This tool displays data related to Pokémon!",
3131
"\n\n", styleBold.Render("USAGE:"),
3232
fmt.Sprintf("\n\t%-15s %s", "poke-cli [flag]", ""),
33-
fmt.Sprintf("\n\t%-15s %s", "poke-cli [command] [flag]", ""),
34-
fmt.Sprintf("\n\t%-15s %s", "poke-cli [command] [subcommand] [flag]", ""),
33+
fmt.Sprintf("\n\t%-15s %s", "poke-cli <command> [flag]", ""),
34+
fmt.Sprintf("\n\t%-15s %s", "poke-cli <command> <subcommand> [flag]", ""),
3535
"\n\n", styleBold.Render("FLAGS:"),
3636
fmt.Sprintf("\n\t%-15s %s", "-h, --help", "Shows the help menu"),
3737
fmt.Sprintf("\n\t%-15s %s", "-l, --latest", "Prints the latest available"),
@@ -43,9 +43,12 @@ func runCLI(args []string) int {
4343
fmt.Println(helpMessage)
4444
}
4545

46-
// Check for help flag manually
47-
for _, arg := range args {
48-
if arg == "-h" || arg == "--help" {
46+
switch {
47+
case len(args) == 0:
48+
mainFlagSet.Usage()
49+
return 0
50+
case len(args) > 0:
51+
if args[0] == "-h" || args[0] == "--help" {
4952
mainFlagSet.Usage()
5053
return 0
5154
}
@@ -71,8 +74,10 @@ func runCLI(args []string) int {
7174
cmdFunc()
7275
return 0
7376
} else {
77+
command := os.Args[1]
7478
errMessage := errorBorder.Render(
7579
errorColor.Render("Error!"),
80+
fmt.Sprintf("\n\t%-15s", fmt.Sprintf("'%s' is not a valid command.\n", command)),
7681
styleBold.Render("\nAvailable Commands:"),
7782
fmt.Sprintf("\n\t%-15s %s", "pokemon", "Get details of a specific Pokémon"),
7883
fmt.Sprintf("\n\t%-15s %s", "types", "Get details of a specific typing\n"),
@@ -83,7 +88,7 @@ func runCLI(args []string) int {
8388
}
8489
}
8590

86-
var exit = os.Exit // Default to os.Exit, but you can override this in tests
91+
var exit = os.Exit
8792

8893
func main() {
8994
exit(runCLI(os.Args[1:]))

cli_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func stripANSI(input string) string {
1717
}
1818

1919
func TestMainFunction(t *testing.T) {
20-
version := "v0.6.5"
20+
version := "v0.7.0"
2121

2222
// Backup the original exit function and stdout/stderr
2323
originalExit := exit
@@ -42,6 +42,8 @@ func TestMainFunction(t *testing.T) {
4242
args: []string{"pokemons"},
4343
expectedOutput: "╭──────────────────────────────────────────────────────╮\n" +
4444
"│Error! │\n" +
45+
"│ 'pokemons' is not a valid command. │\n" +
46+
"│ │\n" +
4547
"│Available Commands: │\n" +
4648
"│ pokemon Get details of a specific Pokémon │\n" +
4749
"│ types Get details of a specific typing │\n" +
@@ -67,8 +69,8 @@ func TestMainFunction(t *testing.T) {
6769
"│ │\n" +
6870
"│ USAGE: │\n" +
6971
"│ poke-cli [flag] │\n" +
70-
"│ poke-cli [command] [flag] │\n" +
71-
"│ poke-cli [command] [subcommand] [flag] │\n" +
72+
"│ poke-cli <command> [flag] │\n" +
73+
"│ poke-cli <command> <subcommand> [flag] │\n" +
7274
"│ │\n" +
7375
"│ FLAGS: │\n" +
7476
"│ -h, --help Shows the help menu │\n" +

cmd/pokemon.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,15 @@ func PokemonCommand() {
1616

1717
flag.Usage = func() {
1818
helpMessage := helpBorder.Render(
19+
"Get details about a specific Pokémon.\n\n",
1920
styleBold.Render("USAGE:"),
2021
fmt.Sprintf("\n\t%s %s %s %s", "poke-cli", styleBold.Render("pokemon"), "<pokemon-name>", "[flag]"),
21-
fmt.Sprintf("\n\t%-30s", "Get details about a specific Pokémon"),
22-
fmt.Sprintf("\n\t%-30s", "----------"),
23-
fmt.Sprintf("\n\t%-30s", styleItalic.Render("Examples:\n")),
24-
fmt.Sprintf("\n\t%-30s", "poke-cli pokemon bulbasaur"),
25-
fmt.Sprintf("\n\t%-30s", "poke-cli pokemon flutter-mane --types"),
26-
fmt.Sprintf("\n\t%-30s", "poke-cli pokemon excadrill -t -a"),
22+
fmt.Sprintf("\n\t%-30s", styleItalic.Render("Use a hyphen when typing a name with a space.")),
2723
"\n\n",
2824
styleBold.Render("FLAGS:"),
2925
fmt.Sprintf("\n\t%-30s %s", "-a, --abilities", "Prints out the Pokémon's abilities."),
3026
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."),
3128
)
3229
fmt.Println(helpMessage)
3330
}

cmd/types.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,12 @@ func TypesCommand() {
193193

194194
flag.Usage = func() {
195195
helpMessage := helpBorder.Render(
196+
"Get details about a specific typing.\n\n",
196197
styleBold.Render("USAGE:"),
197198
fmt.Sprintf("\n\t%s %s %s", "poke-cli", styleBold.Render("types"), "[flag]"),
198-
fmt.Sprintf("\n\t%-30s", "Get details about a specific typing"),
199-
fmt.Sprintf("\n\t%-30s", "----------"),
200-
fmt.Sprintf("\n\t%-30s", styleItalic.Render("Examples:")),
201-
fmt.Sprintf("\n\t%-30s", "poke-cli types"),
202-
fmt.Sprintf("\n\t%-30s", "A table will then display with the option to select a type."),
199+
"\n\n",
200+
styleBold.Render("FLAGS:"),
201+
fmt.Sprintf("\n\t%-30s %s", "-h, --help", "Prints out the help menu."),
203202
)
204203
fmt.Println(helpMessage)
205204
}

cmd/validateargs.go

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,33 @@ import (
66
"os"
77
)
88

9+
func handleHelpFlag(args []string) {
10+
if len(args) == 3 && (args[2] == "-h" || args[2] == "--help") {
11+
flag.Usage()
12+
13+
if flag.Lookup("test.v") == nil {
14+
os.Exit(0)
15+
}
16+
}
17+
}
18+
919
// ValidatePokemonArgs validates the command line arguments
1020
func ValidatePokemonArgs(args []string) error {
1121

12-
if len(args) > 5 {
13-
errMessage := errorBorder.Render(errorColor.Render("Error!"), "\nToo many arguments")
22+
handleHelpFlag(args)
23+
24+
if len(args) < 3 {
25+
errMessage := errorBorder.Render(
26+
errorColor.Render("Error!"),
27+
"\nPlease declare a Pokémon's name after the [pokemon] command",
28+
"\nRun 'poke-cli pokemon -h' for more details",
29+
"\nerror: insufficient arguments",
30+
)
1431
return fmt.Errorf("%s", errMessage)
1532
}
1633

17-
if len(args) < 3 {
18-
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")
34+
if len(args) > 5 {
35+
errMessage := errorBorder.Render(errorColor.Render("Error!"), "\nToo many arguments")
1936
return fmt.Errorf("%s", errMessage)
2037
}
2138

@@ -31,16 +48,14 @@ func ValidatePokemonArgs(args []string) error {
3148
}
3249
}
3350

34-
if args[2] == "-h" || args[2] == "--help" {
35-
flag.Usage()
36-
return fmt.Errorf("")
37-
}
38-
3951
return nil
4052
}
4153

4254
// ValidateTypesArgs validates the command line arguments
4355
func ValidateTypesArgs(args []string) error {
56+
57+
handleHelpFlag(args)
58+
4459
if len(args) > 3 {
4560
errMessage := errorBorder.Render(errorColor.Render("Error!"), "\nToo many arguments")
4661
return fmt.Errorf("%s", errMessage)
@@ -54,16 +69,7 @@ func ValidateTypesArgs(args []string) error {
5469
finalErrorMessage := errorTitle + errorString
5570
renderedError := errorBorder.Render(finalErrorMessage)
5671
return fmt.Errorf("%s", renderedError)
57-
58-
// Check if there are exactly 3 arguments and the third argument is either '-h' or '--help'
59-
// If true, display the usage information
60-
} else if len(args) == 3 && (args[2] == "-h" || args[2] == "--help") {
61-
flag.Usage()
62-
63-
// Only call os.Exit if not in test mode
64-
if flag.Lookup("test.v") == nil {
65-
os.Exit(0)
66-
}
6772
}
73+
6874
return nil
6975
}

connections/connection.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package connections
22

33
import (
44
"encoding/json"
5+
"flag"
56
"fmt"
67
"github.com/charmbracelet/lipgloss"
78
"io"
89
"net/http"
10+
"os"
911
)
1012

1113
type PokemonJSONStruct struct {
@@ -79,8 +81,13 @@ func ApiCallSetup(url string, target interface{}) error {
7981
defer res.Body.Close()
8082

8183
if res.StatusCode == http.StatusNotFound {
82-
fmt.Println(errorColor.Render("Page not found. 404 error."))
83-
return fmt.Errorf("page not found: 404 error")
84+
fmt.Println(errorColor.Render("Pokémon not found. Perhaps a typo in the name?"))
85+
86+
if flag.Lookup("test.v") != nil {
87+
return fmt.Errorf("page not found: 404 error")
88+
} else {
89+
os.Exit(1)
90+
}
8491
}
8592

8693
body, err := io.ReadAll(res.Body)

flags/version.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@ func latestDockerImage() {
2121
fmt.Print("Latest Docker image version: ", string(output))
2222
}
2323

24-
func latestRelease() {
24+
func latestRelease(githubAPIURL string) {
2525
type Release struct {
2626
TagName string `json:"tag_name"`
2727
}
2828

29-
url := "https://api.github.com/repos/digitalghost-dev/poke-cli/releases/latest"
30-
31-
response, err := http.Get(url)
29+
response, err := http.Get(githubAPIURL)
3230
if err != nil {
3331
fmt.Println("Error fetching data:", err)
3432
return
@@ -58,5 +56,5 @@ func latestRelease() {
5856
func LatestFlag() {
5957
// cmd := exec.Command("git", "describe", "--tags", "--abbrev=0")
6058
latestDockerImage()
61-
latestRelease()
59+
latestRelease("https://api.github.com/repos/digitalghost-dev/poke-cli/releases/latest")
6260
}

0 commit comments

Comments
 (0)