From a2d8817f7693e4bf51f62f69acbd405bb2a879a1 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 7 Oct 2024 14:22:39 -0700 Subject: [PATCH 1/3] updating version numbers --- .github/workflows/ci.yml | 2 +- README.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef0f996..2f5779e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ on: branches: - main env: - VERSION_NUMBER: 'v0.6.1' + VERSION_NUMBER: 'v0.6.2' REGISTRY_NAME: digitalghostdev/poke-cli jobs: diff --git a/README.md b/README.md index 7971dbd..aceb6ee 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ pokemon-logo

Pokémon CLI

version-label - docker-image-size + docker-image-size
@@ -38,7 +38,7 @@ _Taskfile can build the executable for you_ _Use a Docker Image_ ```bash -docker run --rm -it digitalghostdev/poke-cli:v0.6.0 [command] [subcommand] [flag] +docker run --rm -it digitalghostdev/poke-cli:v0.6.2 [command] [subcommand] [flag] ``` ### Go Build From c02b1ee39e368e268988fe34a4de3ca65866557f Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 7 Oct 2024 15:36:14 -0700 Subject: [PATCH 2/3] improved error handling and help flag logic (#49) --- cmd/validateargs.go | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/cmd/validateargs.go b/cmd/validateargs.go index 499ee91..b857f21 100644 --- a/cmd/validateargs.go +++ b/cmd/validateargs.go @@ -3,6 +3,7 @@ package cmd import ( "flag" "fmt" + "os" ) // ValidatePokemonArgs validates the command line arguments @@ -23,8 +24,8 @@ func ValidatePokemonArgs(args []string) error { if arg[0] != '-' { 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 - renderedError := errorBorder.Render(formattedString) + finalErrorMessage := errorTitle + errorString + renderedError := errorBorder.Render(finalErrorMessage) return fmt.Errorf("%s", renderedError) } } @@ -45,10 +46,24 @@ func ValidateTypesArgs(args []string) error { return fmt.Errorf("%s", errMessage) } + // Check if there are exactly 3 arguments and the third argument is neither '-h' nor '--help' + // If true, return an error message since only '-h' and '--help' are allowed after 'types' if len(args) == 3 && (args[2] != "-h" && args[2] != "--help") { - errMessage := errorBorder.Render("Error! The only currently available options\nafter [types] command is '-h' or '--help'") - return fmt.Errorf("%s", errMessage) - } + errorTitle := errorColor.Render("Error!") + errorString := "\nThe only currently available options\nafter [types] command are '-h' or '--help'" + finalErrorMessage := errorTitle + errorString + renderedError := errorBorder.Render(finalErrorMessage) + return fmt.Errorf("%s", renderedError) + + // Check if there are exactly 3 arguments and the third argument is either '-h' or '--help' + // If true, display the usage information + } else if len(args) == 3 && (args[2] == "-h" || args[2] == "--help") { + flag.Usage() + // Only call os.Exit if not in test mode + if flag.Lookup("test.v") == nil { + os.Exit(0) + } + } return nil } From 5db02dbfa5ffdcb2d03283e62c141a901147f06a Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 7 Oct 2024 15:37:05 -0700 Subject: [PATCH 3/3] move help flag validation to ValidateTypesArgs function (#48) --- cmd/types.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/cmd/types.go b/cmd/types.go index 88f22cd..d02f7e8 100644 --- a/cmd/types.go +++ b/cmd/types.go @@ -87,11 +87,6 @@ func TypesCommand() { os.Exit(1) } - if len(args) == 3 && (args[2] == "-h" || args[2] == "--help") { - flag.Usage() - return - } - columns := []table.Column{ {Title: "Type", Width: 16}, }