Skip to content

Commit bd6b721

Browse files
committed
feat: update go & include latest mc version in mc version command
1 parent 502cd86 commit bd6b721

File tree

7 files changed

+42
-9
lines changed

7 files changed

+42
-9
lines changed

.github/workflows/quality.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v3
13-
- uses: actions/setup-go@v3
13+
- uses: actions/setup-go@v5
14+
with:
15+
go-version: '^1.23.2'
1416
- name: Install goimports
1517
run: |
1618
go install golang.org/x/tools/cmd/goimports@latest

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 Matt Worzala
3+
Copyright (c) 2024 Matt Worzala
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

cmd/mc/version.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,22 @@ func newVersionCmd(app *cli.App) *cobra.Command {
2121
state = "modified"
2222
}
2323

24+
latestRelease, latestSnapshot, err := app.VersionManager().LatestVersions()
25+
if err != nil {
26+
return err
27+
}
28+
2429
return app.Present(&appModel.Version{
2530
Tag: app.Build.Version,
2631
Commit: app.Build.Commit,
2732
State: state,
2833
Date: app.Build.Date,
2934
Go: runtime.Version(),
3035
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
36+
Game: appModel.GameVersion{
37+
Release: latestRelease,
38+
Snapshot: latestSnapshot,
39+
},
3140
})
3241
},
3342
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/mworzala/mc
22

3-
go 1.19
3+
go 1.23.2
44

55
require (
66
github.com/MakeNowJust/heredoc v1.0.0

go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
6767
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
6868
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
6969
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
70+
github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
7071
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
7172
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
7273
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
@@ -111,6 +112,7 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
111112
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
112113
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
113114
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
115+
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
114116
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
115117
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
116118
github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
@@ -145,9 +147,11 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
145147
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
146148
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
147149
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
150+
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
148151
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
149152
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
150153
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
154+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
151155
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
152156
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
153157
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
@@ -171,6 +175,7 @@ github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
171175
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
172176
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
173177
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
178+
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
174179
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
175180
github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM=
176181
github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ=

internal/pkg/cli/model/version.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ type Version struct {
1414
Date string
1515
Go string
1616
Platform string
17+
Game GameVersion
18+
}
19+
20+
type GameVersion struct {
21+
Release string
22+
Snapshot string
1723
}
1824

1925
func (v *Version) String() string {
@@ -22,7 +28,10 @@ func (v *Version) String() string {
2228
if v.State != "clean" {
2329
modified = "*"
2430
}
25-
return fmt.Sprintf("mc-cli dev%s", modified)
31+
return heredoc.Docf(`
32+
mc-cli dev%s
33+
minecraft %s (%s)`,
34+
modified, v.Game.Release, v.Game.Snapshot)
2635
}
2736

2837
date := ""
@@ -33,5 +42,6 @@ func (v *Version) String() string {
3342
return heredoc.Docf(`
3443
mc-cli version %s%s
3544
https://github.com/mworzala/mc/releases/tag/v%s
36-
`, v.Tag, date, v.Tag)
45+
minecraft %s (%s)`,
46+
v.Tag, date, v.Tag, v.Game.Release, v.Game.Snapshot)
3747
}

internal/pkg/game/version.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,26 @@ func NewVersionManager(dataDir string) (*VersionManager, error) {
110110
m.manifestV2 = &manifest
111111
}
112112

113-
//todo update if old
114-
115113
return m, nil
116114
}
117115

116+
func (m *VersionManager) LatestVersions() (release, snapshot string, err error) {
117+
if m.manifestV2.LastUpdated.Before(time.Now().Add(-10 * time.Minute)) {
118+
m.triedToUpdate = true
119+
_ = m.updateManifest()
120+
}
121+
122+
return m.manifestV2.Vanilla.Release, m.manifestV2.Vanilla.Snapshot, nil
123+
}
124+
118125
func (m *VersionManager) FindVanilla(name string) (*gameModel.VersionInfo, error) {
119126
v, ok := m.manifestV2.Vanilla.Versions[strings.ToLower(name)]
120127
if !ok {
121128
if m.triedToUpdate {
122129
return nil, ErrUnknownVersion
123130
}
124131
m.triedToUpdate = true
125-
m.updateManifest()
132+
_ = m.updateManifest()
126133
return m.FindVanilla(name)
127134
}
128135
m.triedToUpdate = false
@@ -140,7 +147,7 @@ func (m *VersionManager) FindFabric(name, loader string) (*gameModel.VersionInfo
140147
return nil, ErrUnknownFabricVersion
141148
}
142149
m.triedToUpdate = true
143-
m.updateManifest()
150+
_ = m.updateManifest()
144151
return m.FindFabric(name, loader)
145152
}
146153
m.triedToUpdate = false

0 commit comments

Comments
 (0)