Skip to content
Merged

1.7.4 #200

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ on:
- main

env:
VERSION_NUMBER: 'v1.7.3'
VERSION_NUMBER: 'v1.7.4'
DOCKERHUB_REGISTRY_NAME: 'digitalghostdev/poke-cli'
AWS_REGION: 'us-west-2'

Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yml
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=v1.7.3
- -s -w -X main.version=v1.7.4

archives:
- formats: [ 'zip' ]
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# build 1
FROM golang:1.24.6-alpine3.22 AS build
FROM golang:1.24.9-alpine3.22 AS build

WORKDIR /app

Expand All @@ -8,7 +8,7 @@ RUN go mod download

COPY . .

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

# build 2
FROM --platform=$BUILDPLATFORM alpine:3.22
Expand Down
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="pokemon.svg" 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/v1.7.3?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/v1.7.4?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 @@ -94,11 +94,11 @@ Cloudsmith is a fully cloud-based service that lets you easily create, store, an
3. Choose how to interact with the container:
* Run a single command and exit:
```bash
docker run --rm -it digitalghostdev/poke-cli:v1.7.3 <command> [subcommand] flag]
docker run --rm -it digitalghostdev/poke-cli:v1.7.4 <command> [subcommand] flag]
```
* Enter the container and use its shell:
```bash
docker run --rm -it --name poke-cli --entrypoint /bin/sh digitalghostdev/poke-cli:v1.7.3 -c "cd /app && exec sh"
docker run --rm -it --name poke-cli --entrypoint /bin/sh digitalghostdev/poke-cli:v1.7.4 -c "cd /app && exec sh"
# placed into the /app directory, run the program with './poke-cli'
# example: ./poke-cli ability swift-swim
```
Expand Down
2 changes: 1 addition & 1 deletion card_data/pipelines/poke_cli_dbt/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'poke_cli_dbt'
version: '1.7.3'
version: '1.7.4'

profile: 'poke_cli_dbt'

Expand Down
5 changes: 4 additions & 1 deletion cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ func runCLI(args []string) int {
mainFlagSet.Usage()
return 1
case *latestFlag || *shortLatestFlag:
_, _ = flags.LatestFlag()
_, err := flags.LatestFlag()
if err != nil {
return 1
}
return 0
case *currentVersionFlag || *shortCurrentVersionFlag:
currentVersion()
Expand Down
158 changes: 158 additions & 0 deletions cmd/utils/validateargs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,125 @@ func TestValidatePokemonArgs(t *testing.T) {
}
}

// TestValidateBerryArgs tests the ValidateBerryArgs function
func TestValidateBerryArgs(t *testing.T) {
validInputs := [][]string{
{"poke-cli", "berry"},
{"poke-cli", "berry", "--help"},
}

for _, input := range validInputs {
err := ValidateBerryArgs(input)
require.NoError(t, err, "Expected no error for valid input")
}

invalidInputs := [][]string{
{"poke-cli", "berry", "oran"},
}

for _, input := range invalidInputs {
err := ValidateBerryArgs(input)
require.Error(t, err, "Expected error for invalid input")
}

tooManyArgs := [][]string{
{"poke-cli", "berry", "oran", "sitrus"},
}

expectedError := styling.StripANSI("╭──────────────────╮\n│✖ Error! │\n│Too many arguments│\n╰──────────────────╯")

for _, input := range tooManyArgs {
err := ValidateBerryArgs(input)

if err == nil {
t.Fatalf("Expected an error for input %v, but got nil", input)
}

strippedErr := styling.StripANSI(err.Error())
assert.Equal(t, expectedError, strippedErr, "Unexpected error message for invalid input")
}
}

// TestValidateItemArgs tests the ValidateItemArgs function
func TestValidateItemArgs(t *testing.T) {
validInputs := [][]string{
{"poke-cli", "item", "--help"},
{"poke-cli", "item", "potion"},
{"poke-cli", "item", "master-ball"},
}

for _, input := range validInputs {
err := ValidateItemArgs(input)
require.NoError(t, err, "Expected no error for valid input")
}

invalidInputs := [][]string{
{"poke-cli", "item"},
}

for _, input := range invalidInputs {
err := ValidateItemArgs(input)
require.Error(t, err, "Expected error for invalid input")
}

tooManyArgs := [][]string{
{"poke-cli", "item", "potion", "super-potion"},
}

expectedError := styling.StripANSI("╭──────────────────╮\n│✖ Error! │\n│Too many arguments│\n╰──────────────────╯")

for _, input := range tooManyArgs {
err := ValidateItemArgs(input)

if err == nil {
t.Fatalf("Expected an error for input %v, but got nil", input)
}

strippedErr := styling.StripANSI(err.Error())
assert.Equal(t, expectedError, strippedErr, "Unexpected error message for invalid input")
}
}

// TestValidateMoveArgs tests the ValidateMoveArgs function
func TestValidateMoveArgs(t *testing.T) {
validInputs := [][]string{
{"poke-cli", "move", "--help"},
{"poke-cli", "move", "thunderbolt"},
{"poke-cli", "move", "Dragon-Tail"},
}

for _, input := range validInputs {
err := ValidateMoveArgs(input)
require.NoError(t, err, "Expected no error for valid input")
}

invalidInputs := [][]string{
{"poke-cli", "move"},
}

for _, input := range invalidInputs {
err := ValidateMoveArgs(input)
require.Error(t, err, "Expected error for invalid input")
}

tooManyArgs := [][]string{
{"poke-cli", "move", "tackle", "scratch"},
}

expectedError := styling.StripANSI("╭──────────────────╮\n│✖ Error! │\n│Too many arguments│\n╰──────────────────╯")

for _, input := range tooManyArgs {
err := ValidateMoveArgs(input)

if err == nil {
t.Fatalf("Expected an error for input %v, but got nil", input)
}

strippedErr := styling.StripANSI(err.Error())
assert.Equal(t, expectedError, strippedErr, "Unexpected error message for invalid input")
}
}

// TestValidateSearchArgs tests the ValidateSearchArgs function
func TestValidateSearchArgs(t *testing.T) {
validInputs := [][]string{
Expand Down Expand Up @@ -262,3 +381,42 @@ func TestValidateTypesArgs(t *testing.T) {
assert.Equal(t, expectedError, strippedErr, "Unexpected error message for invalid input")
}
}

// TestValidateSpeedArgs tests the ValidateSpeedArgs function
func TestValidateSpeedArgs(t *testing.T) {
validInputs := [][]string{
{"poke-cli", "speed"},
{"poke-cli", "speed", "--help"},
}

for _, input := range validInputs {
err := ValidateSpeedArgs(input)
require.NoError(t, err, "Expected no error for valid input")
}

invalidInputs := [][]string{
{"poke-cli", "speed", "100"},
}

for _, input := range invalidInputs {
err := ValidateSpeedArgs(input)
require.Error(t, err, "Expected error for invalid input")
}

tooManyArgs := [][]string{
{"poke-cli", "speed", "100", "200"},
}

expectedError := styling.StripANSI("╭──────────────────╮\n│✖ Error! │\n│Too many arguments│\n╰──────────────────╯")

for _, input := range tooManyArgs {
err := ValidateSpeedArgs(input)

if err == nil {
t.Fatalf("Expected an error for input %v, but got nil", input)
}

strippedErr := styling.StripANSI(err.Error())
assert.Equal(t, expectedError, strippedErr, "Unexpected error message for invalid input")
}
}
43 changes: 25 additions & 18 deletions flags/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package flags

import (
"encoding/json"
"errors"
"flag"
"fmt"
"io"
Expand All @@ -16,58 +17,62 @@ import (
func LatestFlag() (string, error) {
var output strings.Builder

latestRelease(&output)
err := latestRelease(&output)

result := output.String()
fmt.Print(result)

return result, nil
return result, err
}

func latestRelease(output *strings.Builder) {
func latestRelease(output *strings.Builder) error {
type Release struct {
TagName string `json:"tag_name"`
}

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

// Implementing gosec error
if flag.Lookup("test.v") == nil {
if parsedURL.Scheme != "https" {
fmt.Fprint(output, "only HTTPS URLs are allowed for security reasons\n")
return
err := errors.New("only HTTPS URLs are allowed for security reasons")
fmt.Fprintln(output, err)
return err
}
if parsedURL.Host != "api.github.com" {
fmt.Fprint(output, "url host is not allowed\n")
return
err := errors.New("url host is not allowed")
fmt.Fprintln(output, err)
return err
}
}

response, err := http.Get(parsedURL.String())
if err != nil {
fmt.Fprintf(output, "error fetching data: %v\n", err)
return
err = fmt.Errorf("error fetching data: %w", err)
fmt.Fprintln(output, err)
return err
}
defer response.Body.Close()

body, err := io.ReadAll(response.Body)
if err != nil {
fmt.Fprintf(output, "error reading response body: %v\n", err)
return
err = fmt.Errorf("error reading response body: %w", err)
fmt.Fprintln(output, err)
return err
}

var release Release
if err := json.Unmarshal(body, &release); err != nil {
fmt.Fprintf(output, "error unmarshalling JSON: %v\n", err)
return
err = fmt.Errorf("error unmarshalling JSON: %w", err)
fmt.Fprintln(output, err)
return err
}

releaseString := "Latest available version:"
releaseString := "Latest available release on GitHub:"
releaseTag := styling.ColoredBullet.Render("") + release.TagName

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

output.WriteString(docStyle.Render(fullDoc))
output.WriteString("\n")

return nil
}
11 changes: 10 additions & 1 deletion flags/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/digitalghost-dev/poke-cli/cmd/utils"
"github.com/digitalghost-dev/poke-cli/styling"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestLatestVersionFlag(t *testing.T) {
Expand All @@ -32,11 +33,13 @@ func TestLatestVersionFlag(t *testing.T) {
name: "Get latest version with short flag",
args: []string{"-l"},
expectedOutput: utils.LoadGolden(t, "main_latest_flag.golden"),
expectedError: false,
},
{
name: "Get latest version with long flag",
args: []string{"--latest"},
expectedOutput: utils.LoadGolden(t, "main_latest_flag.golden"),
expectedError: false,
},
}

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

output, _ := LatestFlag()
output, err := LatestFlag()
cleanOutput := styling.StripANSI(output)

if tt.expectedError {
require.Error(t, err, "Expected an error")
} else {
require.NoError(t, err, "Expected no error")
}

assert.Equal(t, tt.expectedOutput, cleanOutput, "Output should match expected")
})
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/digitalghost-dev/poke-cli

go 1.24.6
go 1.24.9

require (
github.com/charmbracelet/bubbles v0.21.0
Expand Down
2 changes: 1 addition & 1 deletion nfpm.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "poke-cli"
arch: "arm64"
platform: "linux"
version: "v1.7.3"
version: "v1.7.4"
section: "default"
version_schema: semver
maintainer: "Christian S"
Expand Down
Loading