Skip to content

Commit f90d674

Browse files
Merge pull request #116 from digitalghost-dev/1.0.2
1.0.2
2 parents c93c817 + e12eba1 commit f90d674

File tree

10 files changed

+94
-47
lines changed

10 files changed

+94
-47
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ on:
2626
- main
2727

2828
env:
29-
VERSION_NUMBER: 'v1.0.1'
29+
VERSION_NUMBER: 'v1.0.2'
3030
DOCKERHUB_REGISTRY_NAME: 'digitalghostdev/poke-cli'
3131
AWS_REGION: 'us-west-2'
3232

.goreleaser.yaml

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.0.1
17+
- -s -w -X main.version=v1.0.2
1818

1919
archives:
2020
- format: tar.gz

Dockerfile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,26 @@ RUN go mod download
88

99
COPY . .
1010

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

1313
# build 2
14-
FROM gcr.io/distroless/static-debian12:nonroot
14+
FROM --platform=$BUILDPLATFORM alpine:latest
15+
16+
# Install only necessary packages and remove them after use
17+
RUN apk add --no-cache shadow && \
18+
addgroup -S poke_group && adduser -S poke_user -G poke_group && \
19+
sed -i 's/^root:.*/root:!*:0:0:root:\/root:\/sbin\/nologin/' /etc/passwd && \
20+
apk del shadow
1521

1622
COPY --from=build /app/poke-cli /app/poke-cli
1723

1824
ENV TERM=xterm-256color
1925
ENV COLOR_OUTPUT=true
2026

27+
# Set correct permissions
28+
RUN chown -R poke_user:poke_group /app
29+
30+
# Switch to non-root user
31+
USER poke_user
32+
2133
ENTRYPOINT ["/app/poke-cli"]

README.md

Lines changed: 26 additions & 8 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.0.1?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.0.2?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">
@@ -26,7 +26,7 @@ View future plans in the [Roadmap](#roadmap) section.
2626
![demo](https://poke-cli-s3-bucket.s3.us-west-2.amazonaws.com/demo-v0.12.0.gif)
2727

2828
---
29-
## Install
29+
## Installation
3030

3131
### Binary
3232
_Download a pre-built binary_
@@ -45,7 +45,7 @@ _Download a pre-built binary_
4545

4646
<summary>View Image of Settings</summary>
4747

48-
![settings](https://pokemon-objects.nyc3.digitaloceanspaces.com/macos_settings.png)
48+
![settings](https://poke-cli-s3-bucket.s3.us-west-2.amazonaws.com/macos_privacy_settings.png)
4949

5050
</details>
5151

@@ -70,13 +70,20 @@ _Use a Docker Image_
7070
* Necessary.
7171
* `-t`: Allocates a terminal (TTY) for a terminal-like session.
7272
* Necessary.
73-
74-
```bash
75-
docker run --rm -i -t digitalghostdev/poke-cli:v1.0.1 <command> [subcommand] flag]
76-
```
73+
3. Choose how to interact with the container:
74+
* Run a single command and exit:
75+
```bash
76+
docker run --rm -it digitalghostdev/poke-cli:v1.0.2 <command> [subcommand] flag]
77+
```
78+
* Enter the container and use its shell:
79+
```bash
80+
docker run --rm -it --name poke-cli --entrypoint /bin/sh digitalghostdev/poke-cli:v1.0.2 -c "cd /app && exec sh"
81+
# placed into the /app directory, run the program with './poke-cli'
82+
# example: ./poke-cli ability swift-swim
83+
```
7784

7885
### Go Install
79-
_If you have Go already, install the executable yourself_
86+
_If you have Go already, install the executable yourself._
8087

8188
1. Run the following command:
8289
```bash
@@ -113,6 +120,7 @@ By running `poke-cli [-h | --help]`, it'll display information on how to use the
113120
```
114121
115122
---
123+
116124
## Roadmap
117125
Below is a list of the planned/completed commands and flags:
118126
@@ -131,3 +139,13 @@ Below is a list of the planned/completed commands and flags:
131139
- [ ] `search`: search for a resource (`ability`, `berry`, `pokemon`, `move`)
132140
- [ ] `speed`: compare speed stats between two Pokémon.
133141
- [x] `types`: get data about a specific typing.
142+
143+
---
144+
## Tested Terminals
145+
| OS | Terminal | Status | Issues |
146+
|---------|--------------------|:------:|-------------------------------|
147+
| macOS | Ghostty || None |
148+
| macOS | Alacritty || None |
149+
| macOS | macOS Terminal | ⚠️ | Images do not render properly |
150+
| Windows | Windows Terminal || None |
151+
| Ubuntu | Standard Terminal || None |

cli_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func TestRunCLI(t *testing.T) {
186186
{
187187
name: "Latest Flag",
188188
args: []string{"-l"},
189-
expectedOutput: "Latest Docker image version: v1.0.0\nLatest release tag: v1.0.0\n",
189+
expectedOutput: "Latest Docker image version: v1.0.1\nLatest release tag: v1.0.1\n",
190190
expectedCode: 0,
191191
},
192192
}

cmd/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ func (m model) View() string {
5858
func displayTypeDetails(typesName string, endpoint string) {
5959

6060
// Setting up variables to style the list
61-
var columnWidth int = 11
61+
var columnWidth = 11
6262
var subtle = lipgloss.AdaptiveColor{Light: "#D9DCCF", Dark: "#383838"}
6363
var list = lipgloss.NewStyle().Border(lipgloss.NormalBorder(), false, true, false, false).BorderForeground(subtle).MarginRight(2).Height(8)
6464
var listHeader = lipgloss.NewStyle().BorderStyle(lipgloss.NormalBorder()).BorderBottom(true).BorderForeground(subtle).MarginRight(2).Render
6565
var listItem = lipgloss.NewStyle().Render
6666
var docStyle = lipgloss.NewStyle().Padding(1, 1, 1, 1)
6767

6868
baseURL := "https://pokeapi.co/api/v2/"
69-
typesStruct, typeName, _, _ := connections.TypesApiCall(endpoint, typesName, baseURL)
69+
typesStruct, typeName, _ := connections.TypesApiCall(endpoint, typesName, baseURL)
7070

7171
// Format selected type
7272
selectedType := cases.Title(language.English).String(typeName)

connections/connection.go

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,13 @@ import (
55
"errors"
66
"flag"
77
"fmt"
8-
"github.com/charmbracelet/lipgloss"
98
"github.com/digitalghost-dev/poke-cli/structs"
9+
"github.com/digitalghost-dev/poke-cli/styling"
1010
"io"
1111
"net/http"
1212
"net/url"
1313
)
1414

15-
var (
16-
errorBorder = lipgloss.NewStyle().
17-
BorderStyle(lipgloss.RoundedBorder()).
18-
BorderForeground(lipgloss.Color("#F2055C"))
19-
errorColor = lipgloss.NewStyle().Foreground(lipgloss.Color("#F2055C"))
20-
)
21-
2215
// ApiCallSetup Helper function to handle API calls and JSON unmarshalling
2316
func ApiCallSetup(rawURL string, target interface{}, skipHTTPSCheck bool) error {
2417
parsedURL, err := url.Parse(rawURL)
@@ -53,15 +46,16 @@ func ApiCallSetup(rawURL string, target interface{}, skipHTTPSCheck bool) error
5346
return nil
5447
}
5548

49+
// AbilityApiCall function for calling the ability endpoint of the pokeAPI
5650
func AbilityApiCall(endpoint string, abilityName string, baseURL string) (structs.AbilityJSONStruct, string, error) {
5751
fullURL := baseURL + endpoint + "/" + abilityName
5852

5953
var abilityStruct structs.AbilityJSONStruct
6054
err := ApiCallSetup(fullURL, &abilityStruct, false)
6155

6256
if err != nil {
63-
errMessage := errorBorder.Render(
64-
errorColor.Render("Error!"),
57+
errMessage := styling.ErrorBorder.Render(
58+
styling.ErrorColor.Render("Error!"),
6559
"\nAbility not found.\n\u2022 Perhaps a typo?\n\u2022 Missing a hyphen instead of a space?",
6660
)
6761
return structs.AbilityJSONStruct{}, "", fmt.Errorf("%s", errMessage)
@@ -70,15 +64,16 @@ func AbilityApiCall(endpoint string, abilityName string, baseURL string) (struct
7064
return abilityStruct, abilityStruct.Name, nil
7165
}
7266

67+
// PokemonApiCall function for calling the pokemon endpoint of the pokeAPI
7368
func PokemonApiCall(endpoint string, pokemonName string, baseURL string) (structs.PokemonJSONStruct, string, int, int, int, error) {
7469
fullURL := baseURL + endpoint + "/" + pokemonName
7570

7671
var pokemonStruct structs.PokemonJSONStruct
7772
err := ApiCallSetup(fullURL, &pokemonStruct, false)
7873

7974
if err != nil {
80-
errMessage := errorBorder.Render(
81-
errorColor.Render("Error!"),
75+
errMessage := styling.ErrorBorder.Render(
76+
styling.ErrorColor.Render("Error!"),
8277
"\nPokémon not found.\n\u2022 Perhaps a typo?\n\u2022 Missing a hyphen instead of a space?",
8378
)
8479
return structs.PokemonJSONStruct{}, "", 0, 0, 0, fmt.Errorf("%s", errMessage)
@@ -87,19 +82,17 @@ func PokemonApiCall(endpoint string, pokemonName string, baseURL string) (struct
8782
return pokemonStruct, pokemonStruct.Name, pokemonStruct.ID, pokemonStruct.Weight, pokemonStruct.Height, nil
8883
}
8984

90-
func TypesApiCall(endpoint string, typesName string, baseURL string) (structs.TypesJSONStruct, string, int, error) {
85+
// TypesApiCall function for calling the type endpoint of the pokeAPI
86+
func TypesApiCall(endpoint string, typesName string, baseURL string) (structs.TypesJSONStruct, string, int) {
9187
fullURL := baseURL + endpoint + "/" + typesName
9288
var typesStruct structs.TypesJSONStruct
9389

9490
err := ApiCallSetup(fullURL, &typesStruct, false)
9591

9692
if err != nil {
97-
errMessage := errorBorder.Render(
98-
errorColor.Render("Error!"),
99-
"\nType not found.\nPerhaps a typo?",
100-
)
101-
return structs.TypesJSONStruct{}, "", 0, fmt.Errorf("%s", errMessage)
93+
fmt.Println(err)
94+
return structs.TypesJSONStruct{}, "", 0
10295
}
10396

104-
return typesStruct, typesStruct.Name, typesStruct.ID, nil
97+
return typesStruct, typesStruct.Name, typesStruct.ID
10598
}

connections/connection_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func TestTypesApiCall(t *testing.T) {
110110
}))
111111
defer ts.Close()
112112

113-
typesStruct, name, id, _ := TypesApiCall("/type", "electric", ts.URL)
113+
typesStruct, name, id := TypesApiCall("/type", "electric", ts.URL)
114114

115115
assert.Equal(t, expectedTypes, typesStruct)
116116
assert.Equal(t, "electric", name)

flags/version.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,37 @@ import (
88
"net/http"
99
"net/url"
1010
"os/exec"
11+
"runtime"
1112
)
1213

13-
func latestDockerImage(fullCommand string) {
14-
cmd := exec.Command("bash", "-c", fullCommand)
14+
func latestDockerImage() {
15+
var cmd *exec.Cmd
16+
17+
if runtime.GOOS == "windows" {
18+
// Windows PowerShell equivalent
19+
cmd = exec.Command("powershell", "-Command", `
20+
$tags = Invoke-RestMethod -Uri "https://hub.docker.com/v2/repositories/digitalghostdev/poke-cli/tags/?page_size=1";
21+
$tags.results[0].name
22+
`)
23+
} else {
24+
// Check if curl is available
25+
_, err := exec.LookPath("curl")
26+
if err == nil {
27+
// Use curl if available
28+
cmd = exec.Command("sh", "-c", `curl -s https://hub.docker.com/v2/repositories/digitalghostdev/poke-cli/tags/?page_size=1 | grep -o '"name":"[^"]*"' | cut -d '"' -f 4`)
29+
} else {
30+
// Use wget as a fallback
31+
cmd = exec.Command("sh", "-c", `wget -qO- https://hub.docker.com/v2/repositories/digitalghostdev/poke-cli/tags/?page_size=1 | grep -o '"name":"[^"]*"' | cut -d '"' -f 4`)
32+
}
33+
}
34+
1535
output, err := cmd.Output()
1636
if err != nil {
17-
fmt.Printf("error running command: %v\n", err)
37+
fmt.Printf("Error running command: %v\n", err)
1838
return
1939
}
2040

21-
fmt.Print("Latest Docker image version: ", string(output))
41+
fmt.Printf("Latest Docker image version: %s", string(output))
2242
}
2343

2444
func latestRelease(githubAPIURL string) {
@@ -75,6 +95,6 @@ func latestRelease(githubAPIURL string) {
7595

7696
func LatestFlag() {
7797
// cmd := exec.Command("git", "describe", "--tags", "--abbrev=0")
78-
latestDockerImage(`curl -s https://hub.docker.com/v2/repositories/digitalghostdev/poke-cli/tags/?page_size=1 | grep -o '"name":"[^"]*"' | cut -d '"' -f 4`)
98+
latestDockerImage()
7999
latestRelease("https://api.github.com/repos/digitalghost-dev/poke-cli/releases/latest")
80100
}

flags/version_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"net/http/httptest"
99
"os"
10+
"runtime"
1011
"testing"
1112
)
1213

@@ -35,15 +36,18 @@ func captureOutput(f func()) string {
3536
}
3637

3738
func TestLatestDockerImage(t *testing.T) {
38-
// Test normal execution with a valid command
39-
validCommand := `curl -s https://hub.docker.com/v2/repositories/digitalghostdev/poke-cli/tags/?page_size=1 | grep -o '"name":"[^"]*"' | cut -d '"' -f 4`
40-
output := captureOutput(func() { latestDockerImage(validCommand) })
39+
output := captureOutput(func() { latestDockerImage() })
40+
4141
assert.Contains(t, output, "Latest Docker image version:")
4242

43-
// Test command failure with an invalid command
44-
invalidCommand := "invalidcommand"
45-
output = captureOutput(func() { latestDockerImage(invalidCommand) })
46-
assert.Contains(t, output, "error running command:")
43+
// Since the actual API response might change, avoid testing the exact version number.
44+
// Instead, check if a non-empty version string is printed.
45+
46+
if runtime.GOOS == "windows" {
47+
assert.Contains(t, output, "\n") // Ensure PowerShell prints something
48+
} else {
49+
assert.Contains(t, output, "\n") // Ensure bash prints something
50+
}
4751
}
4852

4953
func TestLatestRelease(t *testing.T) {

0 commit comments

Comments
 (0)