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 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}, } 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 }