detached 7eee03d

Fix CMD Update: Pass the version from ldflags to the client app

- Refactor main to use a common struct for BuildConfig
- Adjust NewClientApp and NewServerApp to include BuildConfig in initialization
commit
7eee03d4873f7e18e392b82272743e4abc5501c2
author
bnema · · 2023-11-06 16:55 UTC
parent
6ca3069
signature
unsigned
4 files · +23 -18
M cmd/cli/main.go +14 -14
@@ -33,29 +33,29 @@ func Execute(client *cli.App, server *server.App) {
3333 }
3434
3535 func main() {
36- a, err := cli.NewClientApp()
37- if err != nil {
38- fmt.Println("Error initializing app:", err)
39- }
40- s, err := server.NewServerApp()
41- if err != nil {
42- fmt.Println("Error initializing app:", err)
43- }
44-
45- common.DockerInit(&s.Config.ContainerEngine)
46-
4736 build = regexp.MustCompile(`\d+\.\d+\.\d+`).FindString(build)
48- s.Config.Build = common.BuildConfig{
37+ buildInfo := common.BuildConfig{
4938 BuildVersion: build,
5039 BuildCommit: commit,
5140 BuildDate: date,
5241 ProxyURL: "https://gordon-proxy.bnema.dev",
5342 }
5443
55- if s.Config.Build.BuildVersion != "" {
56- fmt.Printf("Gordon version %s\n", s.Config.Build.BuildVersion)
44+ if buildInfo.BuildVersion != "" {
45+ fmt.Printf("Gordon version %s\n", build)
5746 }
5847
48+ a, err := cli.NewClientApp(buildInfo)
49+ if err != nil {
50+ fmt.Println("Error initializing app:", err)
51+ }
52+ s, err := server.NewServerApp(buildInfo)
53+ if err != nil {
54+ fmt.Println("Error initializing app:", err)
55+ }
56+
57+ common.DockerInit(&s.Config.ContainerEngine)
58+
5959 // Check for new version
6060 go func() {
6161 msg, err := common.CheckVersionPeriodically(&s.Config)
@@ -33,29 +33,29 @@ func Execute(client *cli.App, server *server.App) {
33 }33 }
34 34
35 func main() {35 func main() {
36- a, err := cli.NewClientApp()
37- if err != nil {
38- fmt.Println("Error initializing app:", err)
39- }
40- s, err := server.NewServerApp()
41- if err != nil {
42- fmt.Println("Error initializing app:", err)
43- }
44-
45- common.DockerInit(&s.Config.ContainerEngine)
46-
47 build = regexp.MustCompile(`\d+\.\d+\.\d+`).FindString(build)36 build = regexp.MustCompile(`\d+\.\d+\.\d+`).FindString(build)
48- s.Config.Build = common.BuildConfig{37+ buildInfo := common.BuildConfig{
49 BuildVersion: build,38 BuildVersion: build,
50 BuildCommit: commit,39 BuildCommit: commit,
51 BuildDate: date,40 BuildDate: date,
52 ProxyURL: "https://gordon-proxy.bnema.dev",41 ProxyURL: "https://gordon-proxy.bnema.dev",
53 }42 }
54 43
55- if s.Config.Build.BuildVersion != "" {44+ if buildInfo.BuildVersion != "" {
56- fmt.Printf("Gordon version %s\n", s.Config.Build.BuildVersion)45+ fmt.Printf("Gordon version %s\n", build)
57 }46 }
58 47
48+ a, err := cli.NewClientApp(buildInfo)
49+ if err != nil {
50+ fmt.Println("Error initializing app:", err)
51+ }
52+ s, err := server.NewServerApp(buildInfo)
53+ if err != nil {
54+ fmt.Println("Error initializing app:", err)
55+ }
56+
57+ common.DockerInit(&s.Config.ContainerEngine)
58+
59 // Check for new version59 // Check for new version
60 go func() {60 go func() {
61 msg, err := common.CheckVersionPeriodically(&s.Config)61 msg, err := common.CheckVersionPeriodically(&s.Config)
M internal/cli/cmd/update.go +4 -1
@@ -120,8 +120,11 @@ func (p *plugin) update(withBackup bool) error {
120120 return err
121121 }
122122
123+ fmt.Println("Latest version:", latest.Tag)
124+ fmt.Println("Current version:", p.currentVersion)
125+
123126 if compareVersions(strings.TrimPrefix(p.currentVersion, "v"), strings.TrimPrefix(latest.Tag, "v")) <= 0 {
124- color.Green("You already have the latest PocketBase %s.", p.currentVersion)
127+ color.Green("You already have the latest version %s.", p.currentVersion)
125128 return nil
126129 }
127130
@@ -120,8 +120,11 @@ func (p *plugin) update(withBackup bool) error {
120 return err120 return err
121 }121 }
122 122
123+ fmt.Println("Latest version:", latest.Tag)
124+ fmt.Println("Current version:", p.currentVersion)
125+
123 if compareVersions(strings.TrimPrefix(p.currentVersion, "v"), strings.TrimPrefix(latest.Tag, "v")) <= 0 {126 if compareVersions(strings.TrimPrefix(p.currentVersion, "v"), strings.TrimPrefix(latest.Tag, "v")) <= 0 {
124- color.Green("You already have the latest PocketBase %s.", p.currentVersion)127+ color.Green("You already have the latest version %s.", p.currentVersion)
125 return nil128 return nil
126 }129 }
127 130
M internal/cli/newclient.go +4 -2
@@ -11,9 +11,11 @@ type App struct {
1111 }
1212
1313 // NewClientApp initializes a new App with configuration.
14-func NewClientApp() (*App, error) {
14+func NewClientApp(buildConfig common.BuildConfig) (*App, error) {
1515 // Initialize AppConfig
16- config := common.Config{}
16+ config := common.Config{
17+ Build: buildConfig,
18+ }
1719 _, err := config.LoadConfig()
1820 if err != nil {
1921 return nil, fmt.Errorf("failed to load configuration: %w", err)
@@ -11,9 +11,11 @@ type App struct {
11 }11 }
12 12
13 // NewClientApp initializes a new App with configuration.13 // NewClientApp initializes a new App with configuration.
14-func NewClientApp() (*App, error) {14+func NewClientApp(buildConfig common.BuildConfig) (*App, error) {
15 // Initialize AppConfig15 // Initialize AppConfig
16- config := common.Config{}16+ config := common.Config{
17+ Build: buildConfig,
18+ }
17 _, err := config.LoadConfig()19 _, err := config.LoadConfig()
18 if err != nil {20 if err != nil {
19 return nil, fmt.Errorf("failed to load configuration: %w", err)21 return nil, fmt.Errorf("failed to load configuration: %w", err)
M internal/server/newserver.go +1 -1
@@ -10,7 +10,7 @@ import (
1010 "github.com/bnema/gordon/internal/webui"
1111 )
1212
13-func NewServerApp() (*App, error) {
13+func NewServerApp(common.BuildConfig) (*App, error) {
1414 // Initialize AppConfig
1515 config := common.Config{}
1616 _, err := config.LoadConfig()
@@ -10,7 +10,7 @@ import (
10 "github.com/bnema/gordon/internal/webui"10 "github.com/bnema/gordon/internal/webui"
11 )11 )
12 12
13-func NewServerApp() (*App, error) {13+func NewServerApp(common.BuildConfig) (*App, error) {
14 // Initialize AppConfig14 // Initialize AppConfig
15 config := common.Config{}15 config := common.Config{}
16 _, err := config.LoadConfig()16 _, err := config.LoadConfig()

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close