Skip to content

Commit

Permalink
Merge pull request #84 from digitalghost-dev/0.9.1
Browse files Browse the repository at this point in the history
0.9.1
  • Loading branch information
digitalghost-dev authored Dec 9, 2024
2 parents 18350ce + ff5846d commit 1413337
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -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 }}
2 changes: 1 addition & 1 deletion .github/workflows/go_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -22,5 +24,4 @@ go.work
go.work.sum

# env file
.env
dist/
.env
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<img height="250" width="350" src="https://cdn.simpleicons.org/pokemon/FFCC00" alt="pokemon-logo"/>
<h1>Pokémon CLI</h1>
<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">
<img src="https://img.shields.io/docker/image-size/digitalghostdev/poke-cli/v0.9.0?arch=arm64&style=flat-square&logo=docker&logoColor=FFCC00&labelColor=EEE&color=FFCC00" alt="docker-image-size">
<img src="https://img.shields.io/docker/image-size/digitalghostdev/poke-cli/v0.9.1?arch=arm64&style=flat-square&logo=docker&logoColor=FFCC00&labelColor=EEE&color=FFCC00" alt="docker-image-size">
<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" alt="ci-status-badge">
</div>
<div align="center">
Expand Down Expand Up @@ -68,15 +68,15 @@ _Use a Docker Image_
* Necessary.

```bash
docker run --rm -i -t digitalghostdev/poke-cli:v0.9.0 <command> [subcommand] flag]
docker run --rm -i -t digitalghostdev/poke-cli:v0.9.1 <command> [subcommand] flag]
```

### Go Install
_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!
---
Expand Down
2 changes: 1 addition & 1 deletion cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
Expand Down
36 changes: 33 additions & 3 deletions cmd/validateargs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!"),
Expand All @@ -31,23 +31,53 @@ 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)
}
}
}

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

Expand Down
10 changes: 9 additions & 1 deletion connections/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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")
Expand Down
5 changes: 0 additions & 5 deletions qodana.yaml

This file was deleted.

0 comments on commit 1413337

Please sign in to comment.