Skip to content

Commit 740e4de

Browse files
authored
Merge pull request #22 from 0xjuanma/new-flags
feat[flags]: new --update and --version flags
2 parents 8a79209 + 6bc0ef2 commit 740e4de

File tree

6 files changed

+71
-4
lines changed

6 files changed

+71
-4
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
GOOS: ${{ matrix.goos }}
4646
GOARCH: ${{ matrix.goarch }}
4747
run: |
48-
go build -ldflags="-s -w" -o golazo-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.extension }} .
48+
go build -ldflags="-s -w -X github.com/0xjuanma/golazo/cmd.Version=${{ github.ref_name }}" -o golazo-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.extension }} .
4949
5050
- name: Upload artifact
5151
uses: actions/upload-artifact@v4

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111
- **Goal Notifications** - Desktop notifications and terminal beep for new goals in live matches using score-based detection (macOS, Linux, Windows)
12+
- **New CLI Flags** - Added `--version/-v` to display version info and `--update/-u` to self-update to latest release
1213

1314
### Changed
1415
- **Poll Spinner Duration** - Increased "Updating..." spinner display time to 1 second for better visibility

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ A minimalist terminal user interface (TUI) for following football matches in rea
2020
## Installation/Update
2121

2222
> [!IMPORTANT]
23-
> Tool is in active development.
23+
> As of v0.6.0, you can update golazo to the latest version by running:
24+
> ```bash
25+
> golazo --update
26+
> ```
2427
25-
### Using the install script (recommended)
28+
### Using the install/update script (recommended)
2629
2730
**macOS / Linux:**
2831
```bash

cmd/root.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,40 @@ package cmd
33
import (
44
"fmt"
55
"os"
6+
"os/exec"
7+
"runtime"
68

79
"github.com/0xjuanma/golazo/internal/app"
10+
"github.com/0xjuanma/golazo/internal/constants"
11+
"github.com/0xjuanma/golazo/internal/ui"
812
tea "github.com/charmbracelet/bubbletea"
13+
"github.com/charmbracelet/lipgloss"
14+
"github.com/lucasb-eyer/go-colorful"
915
"github.com/spf13/cobra"
1016
)
1117

18+
// Version is set at build time via -ldflags
19+
var Version = "dev"
20+
1221
var mockFlag bool
22+
var updateFlag bool
23+
var versionFlag bool
1324

1425
var rootCmd = &cobra.Command{
1526
Use: "golazo",
1627
Short: "Football match stats and updates in your terminal",
1728
Long: `A modern terminal user interface for real-time football stats and scores, covering multiple leagues and competitions.`,
1829
Run: func(cmd *cobra.Command, args []string) {
30+
if versionFlag {
31+
printVersion()
32+
return
33+
}
34+
35+
if updateFlag {
36+
runUpdate()
37+
return
38+
}
39+
1940
p := tea.NewProgram(app.New(mockFlag), tea.WithAltScreen())
2041
if _, err := p.Run(); err != nil {
2142
fmt.Fprintf(os.Stderr, "Error running application: %v\n", err)
@@ -24,6 +45,40 @@ var rootCmd = &cobra.Command{
2445
},
2546
}
2647

48+
// printVersion displays the ASCII logo with gradient and version.
49+
func printVersion() {
50+
// Render ASCII title with gradient (same as main view)
51+
title := ui.RenderGradientText(constants.ASCIITitle)
52+
53+
// Render version with gradient color (use the end color - red)
54+
endColor, _ := colorful.Hex(constants.GradientEndColor)
55+
versionStyle := lipgloss.NewStyle().Foreground(lipgloss.Color(endColor.Hex()))
56+
versionText := versionStyle.Render(Version)
57+
58+
// Concatenate version after the last line of ASCII art
59+
fmt.Println(title + "" + versionText)
60+
}
61+
62+
// runUpdate executes the install script to update golazo to the latest version.
63+
func runUpdate() {
64+
var cmd *exec.Cmd
65+
66+
if runtime.GOOS == "windows" {
67+
cmd = exec.Command("powershell", "-Command", "irm https://raw.githubusercontent.com/0xjuanma/golazo/main/scripts/install.ps1 | iex")
68+
} else {
69+
cmd = exec.Command("bash", "-c", "curl -fsSL https://raw.githubusercontent.com/0xjuanma/golazo/main/scripts/install.sh | bash")
70+
}
71+
72+
cmd.Stdout = os.Stdout
73+
cmd.Stderr = os.Stderr
74+
cmd.Stdin = os.Stdin
75+
76+
if err := cmd.Run(); err != nil {
77+
fmt.Fprintf(os.Stderr, "Update failed: %v\n", err)
78+
os.Exit(1)
79+
}
80+
}
81+
2782
// Execute runs the root command.
2883
// Errors are written to stderr and the program exits with code 1 on failure.
2984
func Execute() {
@@ -35,4 +90,6 @@ func Execute() {
3590

3691
func init() {
3792
rootCmd.Flags().BoolVar(&mockFlag, "mock", false, "Use mock data for all views instead of real API data")
93+
rootCmd.Flags().BoolVarP(&updateFlag, "update", "u", false, "Update golazo to the latest version")
94+
rootCmd.Flags().BoolVarP(&versionFlag, "version", "v", false, "Display version information")
3895
}

internal/constants/strings.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package constants
22

33
// Menu items
44
const (
5-
MenuStats = "Stats"
5+
MenuStats = "Finished Matches"
66
MenuLiveMatches = "Live Matches"
77
MenuSettings = "Settings"
88
)

internal/ui/menu.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ func RenderMainMenu(width, height, selected int, sp spinner.Model, randomSpinner
9797
)
9898
}
9999

100+
// RenderGradientText applies a gradient (cyan to red) to multi-line text.
101+
// Exported wrapper for external use.
102+
func RenderGradientText(text string) string {
103+
return renderGradientText(text)
104+
}
105+
100106
// renderGradientText applies a gradient (cyan to red) to multi-line text.
101107
func renderGradientText(text string) string {
102108
lines := strings.Split(text, "\n")

0 commit comments

Comments
 (0)