Skip to content

Commit

Permalink
feat: add mod updating
Browse files Browse the repository at this point in the history
  • Loading branch information
mircearoata committed Dec 6, 2023
1 parent e4b02a7 commit a37ad9a
Show file tree
Hide file tree
Showing 3 changed files with 437 additions and 0 deletions.
38 changes: 38 additions & 0 deletions cli/installations.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,44 @@ func (i *Installation) Install(ctx *GlobalContext, updates chan InstallUpdate) e
return nil
}

func (i *Installation) UpdateMods(ctx *GlobalContext, mods []string) error {
if err := i.Validate(ctx); err != nil {
return errors.Wrap(err, "failed to validate installation")
}

lockFile, err := i.LockFile(ctx)
if err != nil {
return errors.Wrap(err, "failed to read lock file")
}

resolver := NewDependencyResolver(ctx.APIClient)

Check failure on line 479 in cli/installations.go

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

cannot use ctx.APIClient (variable of type graphql.Client) as provider.Provider value in argument to NewDependencyResolver: graphql.Client does not implement provider.Provider (missing method GetMod)

Check failure on line 479 in cli/installations.go

View workflow job for this annotation

GitHub Actions / Build

cannot use ctx.APIClient (variable of type graphql.Client) as provider.Provider value in argument to NewDependencyResolver: graphql.Client does not implement provider.Provider (missing method GetMod)

Check failure on line 479 in cli/installations.go

View workflow job for this annotation

GitHub Actions / Lint

cannot use ctx.APIClient (variable of type graphql.Client) as provider.Provider value in argument to NewDependencyResolver: graphql.Client does not implement provider.Provider (missing method GetMod)

Check failure on line 479 in cli/installations.go

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

cannot use ctx.APIClient (variable of type graphql.Client) as provider.Provider value in argument to NewDependencyResolver: graphql.Client does not implement provider.Provider (missing method GetMod)

Check failure on line 479 in cli/installations.go

View workflow job for this annotation

GitHub Actions / Lint

cannot use ctx.APIClient (variable of type graphql.Client) as provider.Provider value in argument to NewDependencyResolver: graphql.Client does not implement provider.Provider (missing method GetMod)

Check failure on line 479 in cli/installations.go

View workflow job for this annotation

GitHub Actions / Build

cannot use ctx.APIClient (variable of type graphql.Client) as provider.Provider value in argument to NewDependencyResolver: graphql.Client does not implement provider.Provider (missing method GetMod)

Check failure on line 479 in cli/installations.go

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

cannot use ctx.APIClient (variable of type graphql.Client) as provider.Provider value in argument to NewDependencyResolver: graphql.Client does not implement provider.Provider (missing method GetMod)

Check failure on line 479 in cli/installations.go

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

cannot use ctx.APIClient (variable of type graphql.Client) as provider.Provider value in argument to NewDependencyResolver: graphql.Client does not implement provider.Provider (missing method GetMod)

gameVersion, err := i.GetGameVersion(ctx)
if err != nil {
return errors.Wrap(err, "failed to detect game version")
}

profile := ctx.Profiles.GetProfile(i.Profile)
if profile == nil {
return errors.New("could not find profile " + i.Profile)
}

for _, modReference := range mods {
delete(lockFile, modReference)

Check failure on line 492 in cli/installations.go

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

invalid argument: lockFile (variable of type *LockFile) is not a map

Check failure on line 492 in cli/installations.go

View workflow job for this annotation

GitHub Actions / Build

invalid argument: lockFile (variable of type *LockFile) is not a map

Check failure on line 492 in cli/installations.go

View workflow job for this annotation

GitHub Actions / Lint

invalid argument: lockFile (variable of type *LockFile) is not a map

Check failure on line 492 in cli/installations.go

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

invalid argument: lockFile (variable of type *LockFile) is not a map

Check failure on line 492 in cli/installations.go

View workflow job for this annotation

GitHub Actions / Lint

invalid argument: lockFile (variable of type *LockFile) is not a map

Check failure on line 492 in cli/installations.go

View workflow job for this annotation

GitHub Actions / Build

invalid argument: lockFile (variable of type *LockFile) is not a map

Check failure on line 492 in cli/installations.go

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

invalid argument: lockFile (variable of type *LockFile) is not a map

Check failure on line 492 in cli/installations.go

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

invalid argument: lockFile (variable of type *LockFile) is not a map
}

newLockFile, err := profile.Resolve(resolver, lockFile, gameVersion)
if err != nil {
return errors.Wrap(err, "failed to resolve dependencies")
}

if err := i.WriteLockFile(ctx, newLockFile); err != nil {
return errors.Wrap(err, "failed to write lock file")
}

return nil
}

func (i *Installation) SetProfile(ctx *GlobalContext, profile string) error {
found := false
for _, p := range ctx.Profiles.Profiles {
Expand Down
7 changes: 7 additions & 0 deletions tea/scenes/main_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ func NewMainMenu(root components.RootModel) tea.Model {
return newModel, newModel.Init()
},
},
utils.SimpleItem[mainMenu]{
ItemTitle: "Update Mods",
Activate: func(msg tea.Msg, currentModel mainMenu) (tea.Model, tea.Cmd) {
newModel := NewUpdateMods(root, currentModel)
return newModel, newModel.Init()
},
},
utils.SimpleItem[mainMenu]{
ItemTitle: "Apply Changes",
Activate: func(msg tea.Msg, currentModel mainMenu) (tea.Model, tea.Cmd) {
Expand Down
Loading

0 comments on commit a37ad9a

Please sign in to comment.