Skip to content

Commit cb457a4

Browse files
Merge pull request #200 from digitalghost-dev/1.7.4
1.7.4
2 parents 49267ac + 1994f14 commit cb457a4

File tree

13 files changed

+227
-32
lines changed

13 files changed

+227
-32
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ on:
3030
- main
3131

3232
env:
33-
VERSION_NUMBER: 'v1.7.3'
33+
VERSION_NUMBER: 'v1.7.4'
3434
DOCKERHUB_REGISTRY_NAME: 'digitalghostdev/poke-cli'
3535
AWS_REGION: 'us-west-2'
3636

.goreleaser.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ builds:
1414
- windows
1515
- darwin
1616
ldflags:
17-
- -s -w -X main.version=v1.7.3
17+
- -s -w -X main.version=v1.7.4
1818

1919
archives:
2020
- formats: [ 'zip' ]

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# build 1
2-
FROM golang:1.24.6-alpine3.22 AS build
2+
FROM golang:1.24.9-alpine3.22 AS build
33

44
WORKDIR /app
55

@@ -8,7 +8,7 @@ RUN go mod download
88

99
COPY . .
1010

11-
RUN go build -ldflags "-X main.version=v1.7.3" -o poke-cli .
11+
RUN go build -ldflags "-X main.version=v1.7.4" -o poke-cli .
1212

1313
# build 2
1414
FROM --platform=$BUILDPLATFORM alpine:3.22

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<img height="250" width="350" src="pokemon.svg" 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/v1.7.3?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/v1.7.4?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" alt="ci-status-badge">
77
</div>
88
<div align="center">
@@ -94,11 +94,11 @@ Cloudsmith is a fully cloud-based service that lets you easily create, store, an
9494
3. Choose how to interact with the container:
9595
* Run a single command and exit:
9696
```bash
97-
docker run --rm -it digitalghostdev/poke-cli:v1.7.3 <command> [subcommand] flag]
97+
docker run --rm -it digitalghostdev/poke-cli:v1.7.4 <command> [subcommand] flag]
9898
```
9999
* Enter the container and use its shell:
100100
```bash
101-
docker run --rm -it --name poke-cli --entrypoint /bin/sh digitalghostdev/poke-cli:v1.7.3 -c "cd /app && exec sh"
101+
docker run --rm -it --name poke-cli --entrypoint /bin/sh digitalghostdev/poke-cli:v1.7.4 -c "cd /app && exec sh"
102102
# placed into the /app directory, run the program with './poke-cli'
103103
# example: ./poke-cli ability swift-swim
104104
```

card_data/pipelines/poke_cli_dbt/dbt_project.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: 'poke_cli_dbt'
2-
version: '1.7.3'
2+
version: '1.7.4'
33

44
profile: 'poke_cli_dbt'
55

cli.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ func runCLI(args []string) int {
130130
mainFlagSet.Usage()
131131
return 1
132132
case *latestFlag || *shortLatestFlag:
133-
_, _ = flags.LatestFlag()
133+
_, err := flags.LatestFlag()
134+
if err != nil {
135+
return 1
136+
}
134137
return 0
135138
case *currentVersionFlag || *shortCurrentVersionFlag:
136139
currentVersion()

cmd/utils/validateargs_test.go

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,125 @@ func TestValidatePokemonArgs(t *testing.T) {
182182
}
183183
}
184184

185+
// TestValidateBerryArgs tests the ValidateBerryArgs function
186+
func TestValidateBerryArgs(t *testing.T) {
187+
validInputs := [][]string{
188+
{"poke-cli", "berry"},
189+
{"poke-cli", "berry", "--help"},
190+
}
191+
192+
for _, input := range validInputs {
193+
err := ValidateBerryArgs(input)
194+
require.NoError(t, err, "Expected no error for valid input")
195+
}
196+
197+
invalidInputs := [][]string{
198+
{"poke-cli", "berry", "oran"},
199+
}
200+
201+
for _, input := range invalidInputs {
202+
err := ValidateBerryArgs(input)
203+
require.Error(t, err, "Expected error for invalid input")
204+
}
205+
206+
tooManyArgs := [][]string{
207+
{"poke-cli", "berry", "oran", "sitrus"},
208+
}
209+
210+
expectedError := styling.StripANSI("╭──────────────────╮\n│✖ Error! │\n│Too many arguments│\n╰──────────────────╯")
211+
212+
for _, input := range tooManyArgs {
213+
err := ValidateBerryArgs(input)
214+
215+
if err == nil {
216+
t.Fatalf("Expected an error for input %v, but got nil", input)
217+
}
218+
219+
strippedErr := styling.StripANSI(err.Error())
220+
assert.Equal(t, expectedError, strippedErr, "Unexpected error message for invalid input")
221+
}
222+
}
223+
224+
// TestValidateItemArgs tests the ValidateItemArgs function
225+
func TestValidateItemArgs(t *testing.T) {
226+
validInputs := [][]string{
227+
{"poke-cli", "item", "--help"},
228+
{"poke-cli", "item", "potion"},
229+
{"poke-cli", "item", "master-ball"},
230+
}
231+
232+
for _, input := range validInputs {
233+
err := ValidateItemArgs(input)
234+
require.NoError(t, err, "Expected no error for valid input")
235+
}
236+
237+
invalidInputs := [][]string{
238+
{"poke-cli", "item"},
239+
}
240+
241+
for _, input := range invalidInputs {
242+
err := ValidateItemArgs(input)
243+
require.Error(t, err, "Expected error for invalid input")
244+
}
245+
246+
tooManyArgs := [][]string{
247+
{"poke-cli", "item", "potion", "super-potion"},
248+
}
249+
250+
expectedError := styling.StripANSI("╭──────────────────╮\n│✖ Error! │\n│Too many arguments│\n╰──────────────────╯")
251+
252+
for _, input := range tooManyArgs {
253+
err := ValidateItemArgs(input)
254+
255+
if err == nil {
256+
t.Fatalf("Expected an error for input %v, but got nil", input)
257+
}
258+
259+
strippedErr := styling.StripANSI(err.Error())
260+
assert.Equal(t, expectedError, strippedErr, "Unexpected error message for invalid input")
261+
}
262+
}
263+
264+
// TestValidateMoveArgs tests the ValidateMoveArgs function
265+
func TestValidateMoveArgs(t *testing.T) {
266+
validInputs := [][]string{
267+
{"poke-cli", "move", "--help"},
268+
{"poke-cli", "move", "thunderbolt"},
269+
{"poke-cli", "move", "Dragon-Tail"},
270+
}
271+
272+
for _, input := range validInputs {
273+
err := ValidateMoveArgs(input)
274+
require.NoError(t, err, "Expected no error for valid input")
275+
}
276+
277+
invalidInputs := [][]string{
278+
{"poke-cli", "move"},
279+
}
280+
281+
for _, input := range invalidInputs {
282+
err := ValidateMoveArgs(input)
283+
require.Error(t, err, "Expected error for invalid input")
284+
}
285+
286+
tooManyArgs := [][]string{
287+
{"poke-cli", "move", "tackle", "scratch"},
288+
}
289+
290+
expectedError := styling.StripANSI("╭──────────────────╮\n│✖ Error! │\n│Too many arguments│\n╰──────────────────╯")
291+
292+
for _, input := range tooManyArgs {
293+
err := ValidateMoveArgs(input)
294+
295+
if err == nil {
296+
t.Fatalf("Expected an error for input %v, but got nil", input)
297+
}
298+
299+
strippedErr := styling.StripANSI(err.Error())
300+
assert.Equal(t, expectedError, strippedErr, "Unexpected error message for invalid input")
301+
}
302+
}
303+
185304
// TestValidateSearchArgs tests the ValidateSearchArgs function
186305
func TestValidateSearchArgs(t *testing.T) {
187306
validInputs := [][]string{
@@ -262,3 +381,42 @@ func TestValidateTypesArgs(t *testing.T) {
262381
assert.Equal(t, expectedError, strippedErr, "Unexpected error message for invalid input")
263382
}
264383
}
384+
385+
// TestValidateSpeedArgs tests the ValidateSpeedArgs function
386+
func TestValidateSpeedArgs(t *testing.T) {
387+
validInputs := [][]string{
388+
{"poke-cli", "speed"},
389+
{"poke-cli", "speed", "--help"},
390+
}
391+
392+
for _, input := range validInputs {
393+
err := ValidateSpeedArgs(input)
394+
require.NoError(t, err, "Expected no error for valid input")
395+
}
396+
397+
invalidInputs := [][]string{
398+
{"poke-cli", "speed", "100"},
399+
}
400+
401+
for _, input := range invalidInputs {
402+
err := ValidateSpeedArgs(input)
403+
require.Error(t, err, "Expected error for invalid input")
404+
}
405+
406+
tooManyArgs := [][]string{
407+
{"poke-cli", "speed", "100", "200"},
408+
}
409+
410+
expectedError := styling.StripANSI("╭──────────────────╮\n│✖ Error! │\n│Too many arguments│\n╰──────────────────╯")
411+
412+
for _, input := range tooManyArgs {
413+
err := ValidateSpeedArgs(input)
414+
415+
if err == nil {
416+
t.Fatalf("Expected an error for input %v, but got nil", input)
417+
}
418+
419+
strippedErr := styling.StripANSI(err.Error())
420+
assert.Equal(t, expectedError, strippedErr, "Unexpected error message for invalid input")
421+
}
422+
}

flags/version.go

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package flags
22

33
import (
44
"encoding/json"
5+
"errors"
56
"flag"
67
"fmt"
78
"io"
@@ -16,58 +17,62 @@ import (
1617
func LatestFlag() (string, error) {
1718
var output strings.Builder
1819

19-
latestRelease(&output)
20+
err := latestRelease(&output)
2021

2122
result := output.String()
2223
fmt.Print(result)
2324

24-
return result, nil
25+
return result, err
2526
}
2627

27-
func latestRelease(output *strings.Builder) {
28+
func latestRelease(output *strings.Builder) error {
2829
type Release struct {
2930
TagName string `json:"tag_name"`
3031
}
3132

32-
// Parse and validate the URL
3333
parsedURL, err := url.Parse("https://api.github.com/repos/digitalghost-dev/poke-cli/releases/latest")
3434
if err != nil {
35-
fmt.Fprintf(output, "invalid URL: %v\n", err)
36-
return
35+
err = fmt.Errorf("invalid URL: %w", err)
36+
fmt.Fprintln(output, err)
37+
return err
3738
}
3839

39-
// Implementing gosec error
4040
if flag.Lookup("test.v") == nil {
4141
if parsedURL.Scheme != "https" {
42-
fmt.Fprint(output, "only HTTPS URLs are allowed for security reasons\n")
43-
return
42+
err := errors.New("only HTTPS URLs are allowed for security reasons")
43+
fmt.Fprintln(output, err)
44+
return err
4445
}
4546
if parsedURL.Host != "api.github.com" {
46-
fmt.Fprint(output, "url host is not allowed\n")
47-
return
47+
err := errors.New("url host is not allowed")
48+
fmt.Fprintln(output, err)
49+
return err
4850
}
4951
}
5052

5153
response, err := http.Get(parsedURL.String())
5254
if err != nil {
53-
fmt.Fprintf(output, "error fetching data: %v\n", err)
54-
return
55+
err = fmt.Errorf("error fetching data: %w", err)
56+
fmt.Fprintln(output, err)
57+
return err
5558
}
5659
defer response.Body.Close()
5760

5861
body, err := io.ReadAll(response.Body)
5962
if err != nil {
60-
fmt.Fprintf(output, "error reading response body: %v\n", err)
61-
return
63+
err = fmt.Errorf("error reading response body: %w", err)
64+
fmt.Fprintln(output, err)
65+
return err
6266
}
6367

6468
var release Release
6569
if err := json.Unmarshal(body, &release); err != nil {
66-
fmt.Fprintf(output, "error unmarshalling JSON: %v\n", err)
67-
return
70+
err = fmt.Errorf("error unmarshalling JSON: %w", err)
71+
fmt.Fprintln(output, err)
72+
return err
6873
}
6974

70-
releaseString := "Latest available version:"
75+
releaseString := "Latest available release on GitHub:"
7176
releaseTag := styling.ColoredBullet.Render("") + release.TagName
7277

7378
docStyle := lipgloss.NewStyle().
@@ -80,4 +85,6 @@ func latestRelease(output *strings.Builder) {
8085

8186
output.WriteString(docStyle.Render(fullDoc))
8287
output.WriteString("\n")
88+
89+
return nil
8390
}

flags/version_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/digitalghost-dev/poke-cli/cmd/utils"
88
"github.com/digitalghost-dev/poke-cli/styling"
99
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
1011
)
1112

1213
func TestLatestVersionFlag(t *testing.T) {
@@ -32,11 +33,13 @@ func TestLatestVersionFlag(t *testing.T) {
3233
name: "Get latest version with short flag",
3334
args: []string{"-l"},
3435
expectedOutput: utils.LoadGolden(t, "main_latest_flag.golden"),
36+
expectedError: false,
3537
},
3638
{
3739
name: "Get latest version with long flag",
3840
args: []string{"--latest"},
3941
expectedOutput: utils.LoadGolden(t, "main_latest_flag.golden"),
42+
expectedError: false,
4043
},
4144
}
4245

@@ -46,9 +49,15 @@ func TestLatestVersionFlag(t *testing.T) {
4649
os.Args = append([]string{"poke-cli"}, tt.args...)
4750
defer func() { os.Args = originalArgs }()
4851

49-
output, _ := LatestFlag()
52+
output, err := LatestFlag()
5053
cleanOutput := styling.StripANSI(output)
5154

55+
if tt.expectedError {
56+
require.Error(t, err, "Expected an error")
57+
} else {
58+
require.NoError(t, err, "Expected no error")
59+
}
60+
5261
assert.Equal(t, tt.expectedOutput, cleanOutput, "Output should match expected")
5362
})
5463
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/digitalghost-dev/poke-cli
22

3-
go 1.24.6
3+
go 1.24.9
44

55
require (
66
github.com/charmbracelet/bubbles v0.21.0

0 commit comments

Comments
 (0)