From 30beb79983d3c526713211a146b5f2a29d866bed Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 8 Dec 2024 21:02:11 -0800 Subject: [PATCH 1/9] initial commit --- LICENSE.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE.md diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..c3cd367 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) [2024] [Christian Sanchez] + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file From e5d200c194b1bb9660c9995cfbdd49a8b79afce2 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 8 Dec 2024 21:09:29 -0800 Subject: [PATCH 2/9] updating go-version to 1.23 --- .github/workflows/go_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go_test.yml b/.github/workflows/go_test.yml index 8d5e481..c320dde 100644 --- a/.github/workflows/go_test.yml +++ b/.github/workflows/go_test.yml @@ -14,7 +14,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: 1.21 + go-version: 1.23 - name: Install dependencies run: | From 92c6f7d3e031afeb1c60e107c2e91854fd0e3632 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 8 Dec 2024 21:10:11 -0800 Subject: [PATCH 3/9] updating version numbers --- .github/workflows/ci.yml | 2 +- .goreleaser.yaml | 2 +- Dockerfile | 2 +- README.md | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 10ac012..8d97b43 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ on: branches: - main env: - VERSION_NUMBER: 'v0.9.0' + VERSION_NUMBER: 'v0.9.1' DOCKERHUB_REGISTRY_NAME: 'digitalghostdev/poke-cli' AWS_REGION: 'us-west-2' diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 46b9119..8eea093 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -14,7 +14,7 @@ builds: - windows - darwin ldflags: - - -s -w -X main.version=v0.9.0 + - -s -w -X main.version=v0.9.1 archives: - format: tar.gz diff --git a/Dockerfile b/Dockerfile index 8f6408f..4c0bb86 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ RUN go mod download COPY . . -RUN go build -ldflags "-X main.version=v0.9.0" -o poke-cli . +RUN go build -ldflags "-X main.version=v0.9.1" -o poke-cli . # build 2 FROM gcr.io/distroless/static-debian12:nonroot diff --git a/README.md b/README.md index 5ec9bb6..9ab8d14 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ pokemon-logo

Pokémon CLI

version-label - docker-image-size + docker-image-size ci-status-badge
@@ -68,7 +68,7 @@ _Use a Docker Image_ * Necessary. ```bash -docker run --rm -i -t digitalghostdev/poke-cli:v0.9.0 [subcommand] flag] +docker run --rm -i -t digitalghostdev/poke-cli:v0.9.1 [subcommand] flag] ``` ### Go Install @@ -76,7 +76,7 @@ _If you have Go already, install the executable yourself_ 1. Run the following command: ```bash - go install github.com/digitalghost-dev/poke-cli@v0 + go install github.com/digitalghost-dev/poke-cli@latest ``` 2. The tool is ready to use! --- From a024a70f31260ac030653d22a755abb335e16ef3 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 8 Dec 2024 21:10:53 -0800 Subject: [PATCH 4/9] initial commit --- .github/workflows/coverage.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/coverage.yml diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 0000000..608d440 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,29 @@ +name: Coverage Report + +on: + pull_request: + types: [opened, reopened, synchronize] + +jobs: + tests: + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.23 + + - name: Install dependencies + run: | + go install . + + - name: Run coverage + run: go test ./... -race -coverprofile=coverage.txt -covermode=atomic + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v5 + with: + token: ${{ secrets.CODECOV_ORG_TOKEN }} \ No newline at end of file From 2a2943ba92e660c611718f30adfc6b92a91a4fe3 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 8 Dec 2024 21:11:08 -0800 Subject: [PATCH 5/9] adding paths to ignore --- .gitignore | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 8d60a31..4d4c59a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,12 +7,14 @@ *.DS_Store *.idea .dccache +dist/ # Test binary, built with `go test -c` *.test # Output of the go coverage tool, specifically when used with LiteIDE *.out +codecov* # Dependency directories (remove the comment below to include it) # vendor/ @@ -22,5 +24,4 @@ go.work go.work.sum # env file -.env -dist/ \ No newline at end of file +.env \ No newline at end of file From 7e018baa081d1c112f96ac4111078f07b03967d6 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 8 Dec 2024 21:11:32 -0800 Subject: [PATCH 6/9] updating tests --- cli_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli_test.go b/cli_test.go index c0876d9..f8d5801 100644 --- a/cli_test.go +++ b/cli_test.go @@ -110,7 +110,7 @@ func TestRunCLI(t *testing.T) { { name: "Latest Flag", args: []string{"-l"}, - expectedOutput: "Latest Docker image version: v0.8.0\nLatest release tag: v0.8.0\n", + expectedOutput: "Latest Docker image version: v0.9.0\nLatest release tag: v0.9.0\n", expectedCode: 0, }, } From b1c8baca32e2befca65d084e7c3de09d91494514 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 8 Dec 2024 21:12:52 -0800 Subject: [PATCH 7/9] removing qodana --- qodana.yaml | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 qodana.yaml diff --git a/qodana.yaml b/qodana.yaml deleted file mode 100644 index e25b860..0000000 --- a/qodana.yaml +++ /dev/null @@ -1,5 +0,0 @@ -version: "1.0" -linter: jetbrains/qodana-go:2024.2 - -profile: - name: qodana.recommended \ No newline at end of file From ba67ce5faf85133cca273659d4f948d3ebdbec8a Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 8 Dec 2024 21:14:08 -0800 Subject: [PATCH 8/9] fixing error message outputs --- cmd/validateargs.go | 36 +++++++++++++++++++++++++++++++++--- connections/connection.go | 10 +++++++++- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/cmd/validateargs.go b/cmd/validateargs.go index 5355e87..6d9bd40 100644 --- a/cmd/validateargs.go +++ b/cmd/validateargs.go @@ -18,9 +18,9 @@ func handleHelpFlag(args []string) { // ValidatePokemonArgs validates the command line arguments func ValidatePokemonArgs(args []string) error { - handleHelpFlag(args) + // Check if the number of arguments is less than 3 if len(args) < 3 { errMessage := errorBorder.Render( errorColor.Render("Error!"), @@ -31,16 +31,37 @@ func ValidatePokemonArgs(args []string) error { return fmt.Errorf("%s", errMessage) } + // Check if there are too many arguments if len(args) > 6 { - errMessage := errorBorder.Render(errorColor.Render("Error!"), "\nToo many arguments") + errMessage := errorBorder.Render( + errorColor.Render("Error!"), + "\nToo many arguments", + ) return fmt.Errorf("%s", errMessage) } + // Validate each argument after the Pokémon's name if len(args) > 3 { for _, arg := range args[3:] { + // Check for single `-` or `--` which are invalid + if arg == "-" || arg == "--" { + errorTitle := errorColor.Render("Error!") + errorString := fmt.Sprintf( + "\nInvalid argument '%s'. Single '-' or '--' is not allowed.\nPlease use valid flags.", + arg, + ) + finalErrorMessage := errorTitle + errorString + renderedError := errorBorder.Render(finalErrorMessage) + return fmt.Errorf("%s", renderedError) + } + + // Check if the argument starts with a flag prefix but is invalid 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) + errorString := fmt.Sprintf( + "\nInvalid argument '%s'.\nOnly flags are allowed after declaring a Pokémon's name", + arg, + ) finalErrorMessage := errorTitle + errorString renderedError := errorBorder.Render(finalErrorMessage) return fmt.Errorf("%s", renderedError) @@ -48,6 +69,15 @@ func ValidatePokemonArgs(args []string) error { } } + // Add a check for invalid Pokémon names (e.g., names starting with `-`) + if len(args[2]) > 0 && args[2][0] == '-' { + errMessage := errorBorder.Render( + errorColor.Render("Error!"), + "\nPokémon not found. Perhaps a typo in the name?", + ) + return fmt.Errorf("%s", errMessage) + } + return nil } diff --git a/connections/connection.go b/connections/connection.go index 071afeb..6f18a58 100644 --- a/connections/connection.go +++ b/connections/connection.go @@ -12,6 +12,10 @@ import ( "os" ) +var errorBorder = lipgloss.NewStyle(). + BorderStyle(lipgloss.RoundedBorder()). + BorderForeground(lipgloss.Color("#F2055C")) + type PokemonJSONStruct struct { Name string `json:"name"` ID int `json:"id"` @@ -108,7 +112,11 @@ func ApiCallSetup(rawURL string, target interface{}, skipHTTPSCheck bool) error defer res.Body.Close() if res.StatusCode == http.StatusNotFound { - fmt.Println(errorColor.Render("Pokémon not found. Perhaps a typo in the name?")) + errMessage := errorBorder.Render( + errorColor.Render("Error!"), + "\nPokémon not found. Perhaps a typo in the name?", + ) + fmt.Println(errMessage) if flag.Lookup("test.v") != nil { return fmt.Errorf("page not found: 404 error") From 92b129a431fa50005521849ed8099d8ca8fbe325 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 8 Dec 2024 21:14:08 -0800 Subject: [PATCH 9/9] fixing error message outputs (#83) --- cmd/validateargs.go | 36 +++++++++++++++++++++++++++++++++--- connections/connection.go | 10 +++++++++- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/cmd/validateargs.go b/cmd/validateargs.go index 5355e87..6d9bd40 100644 --- a/cmd/validateargs.go +++ b/cmd/validateargs.go @@ -18,9 +18,9 @@ func handleHelpFlag(args []string) { // ValidatePokemonArgs validates the command line arguments func ValidatePokemonArgs(args []string) error { - handleHelpFlag(args) + // Check if the number of arguments is less than 3 if len(args) < 3 { errMessage := errorBorder.Render( errorColor.Render("Error!"), @@ -31,16 +31,37 @@ func ValidatePokemonArgs(args []string) error { return fmt.Errorf("%s", errMessage) } + // Check if there are too many arguments if len(args) > 6 { - errMessage := errorBorder.Render(errorColor.Render("Error!"), "\nToo many arguments") + errMessage := errorBorder.Render( + errorColor.Render("Error!"), + "\nToo many arguments", + ) return fmt.Errorf("%s", errMessage) } + // Validate each argument after the Pokémon's name if len(args) > 3 { for _, arg := range args[3:] { + // Check for single `-` or `--` which are invalid + if arg == "-" || arg == "--" { + errorTitle := errorColor.Render("Error!") + errorString := fmt.Sprintf( + "\nInvalid argument '%s'. Single '-' or '--' is not allowed.\nPlease use valid flags.", + arg, + ) + finalErrorMessage := errorTitle + errorString + renderedError := errorBorder.Render(finalErrorMessage) + return fmt.Errorf("%s", renderedError) + } + + // Check if the argument starts with a flag prefix but is invalid 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) + errorString := fmt.Sprintf( + "\nInvalid argument '%s'.\nOnly flags are allowed after declaring a Pokémon's name", + arg, + ) finalErrorMessage := errorTitle + errorString renderedError := errorBorder.Render(finalErrorMessage) return fmt.Errorf("%s", renderedError) @@ -48,6 +69,15 @@ func ValidatePokemonArgs(args []string) error { } } + // Add a check for invalid Pokémon names (e.g., names starting with `-`) + if len(args[2]) > 0 && args[2][0] == '-' { + errMessage := errorBorder.Render( + errorColor.Render("Error!"), + "\nPokémon not found. Perhaps a typo in the name?", + ) + return fmt.Errorf("%s", errMessage) + } + return nil } diff --git a/connections/connection.go b/connections/connection.go index 071afeb..6f18a58 100644 --- a/connections/connection.go +++ b/connections/connection.go @@ -12,6 +12,10 @@ import ( "os" ) +var errorBorder = lipgloss.NewStyle(). + BorderStyle(lipgloss.RoundedBorder()). + BorderForeground(lipgloss.Color("#F2055C")) + type PokemonJSONStruct struct { Name string `json:"name"` ID int `json:"id"` @@ -108,7 +112,11 @@ func ApiCallSetup(rawURL string, target interface{}, skipHTTPSCheck bool) error defer res.Body.Close() if res.StatusCode == http.StatusNotFound { - fmt.Println(errorColor.Render("Pokémon not found. Perhaps a typo in the name?")) + errMessage := errorBorder.Render( + errorColor.Render("Error!"), + "\nPokémon not found. Perhaps a typo in the name?", + ) + fmt.Println(errMessage) if flag.Lookup("test.v") != nil { return fmt.Errorf("page not found: 404 error")