@@ -3,19 +3,40 @@ package cmd
33import (
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+
1221var mockFlag bool
22+ var updateFlag bool
23+ var versionFlag bool
1324
1425var 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.
2984func Execute () {
@@ -35,4 +90,6 @@ func Execute() {
3590
3691func 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}
0 commit comments