Skip to content

Commit

Permalink
feat: update go & include latest mc version in mc version command
Browse files Browse the repository at this point in the history
  • Loading branch information
mworzala committed Oct 3, 2024
1 parent 502cd86 commit bd6b721
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/quality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: actions/setup-go@v5
with:
go-version: '^1.23.2'
- name: Install goimports
run: |
go install golang.org/x/tools/cmd/goimports@latest
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Matt Worzala
Copyright (c) 2024 Matt Worzala

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
9 changes: 9 additions & 0 deletions cmd/mc/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,22 @@ func newVersionCmd(app *cli.App) *cobra.Command {
state = "modified"
}

latestRelease, latestSnapshot, err := app.VersionManager().LatestVersions()
if err != nil {
return err
}

return app.Present(&appModel.Version{
Tag: app.Build.Version,
Commit: app.Build.Commit,
State: state,
Date: app.Build.Date,
Go: runtime.Version(),
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
Game: appModel.GameVersion{
Release: latestRelease,
Snapshot: latestSnapshot,
},
})
},
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/mworzala/mc

go 1.19
go 1.23.2

require (
github.com/MakeNowJust/heredoc v1.0.0
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
Expand Down Expand Up @@ -111,6 +112,7 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
Expand Down Expand Up @@ -145,9 +147,11 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
Expand All @@ -171,6 +175,7 @@ github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM=
github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ=
Expand Down
14 changes: 12 additions & 2 deletions internal/pkg/cli/model/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ type Version struct {
Date string
Go string
Platform string
Game GameVersion
}

type GameVersion struct {
Release string
Snapshot string
}

func (v *Version) String() string {
Expand All @@ -22,7 +28,10 @@ func (v *Version) String() string {
if v.State != "clean" {
modified = "*"
}
return fmt.Sprintf("mc-cli dev%s", modified)
return heredoc.Docf(`
mc-cli dev%s
minecraft %s (%s)`,
modified, v.Game.Release, v.Game.Snapshot)
}

date := ""
Expand All @@ -33,5 +42,6 @@ func (v *Version) String() string {
return heredoc.Docf(`
mc-cli version %s%s
https://github.com/mworzala/mc/releases/tag/v%s
`, v.Tag, date, v.Tag)
minecraft %s (%s)`,
v.Tag, date, v.Tag, v.Game.Release, v.Game.Snapshot)
}
15 changes: 11 additions & 4 deletions internal/pkg/game/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,26 @@ func NewVersionManager(dataDir string) (*VersionManager, error) {
m.manifestV2 = &manifest
}

//todo update if old

return m, nil
}

func (m *VersionManager) LatestVersions() (release, snapshot string, err error) {
if m.manifestV2.LastUpdated.Before(time.Now().Add(-10 * time.Minute)) {
m.triedToUpdate = true
_ = m.updateManifest()
}

return m.manifestV2.Vanilla.Release, m.manifestV2.Vanilla.Snapshot, nil
}

func (m *VersionManager) FindVanilla(name string) (*gameModel.VersionInfo, error) {
v, ok := m.manifestV2.Vanilla.Versions[strings.ToLower(name)]
if !ok {
if m.triedToUpdate {
return nil, ErrUnknownVersion
}
m.triedToUpdate = true
m.updateManifest()
_ = m.updateManifest()
return m.FindVanilla(name)
}
m.triedToUpdate = false
Expand All @@ -140,7 +147,7 @@ func (m *VersionManager) FindFabric(name, loader string) (*gameModel.VersionInfo
return nil, ErrUnknownFabricVersion
}
m.triedToUpdate = true
m.updateManifest()
_ = m.updateManifest()
return m.FindFabric(name, loader)
}
m.triedToUpdate = false
Expand Down

0 comments on commit bd6b721

Please sign in to comment.