Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix app update command and duplicated apps (backport #3931) #3938

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
### Bug Fixes

- [#3905](/~https://github.com/ignite/cli/pull/3905) Fix `ignite completion`
- [#3931](/~https://github.com/ignite/cli/pull/3931) Fix `app update` command and duplicated apps

## [`v28.1.1`](/~https://github.com/ignite/cli/releases/tag/v28.1.1)

Expand Down
8 changes: 6 additions & 2 deletions ignite/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,14 @@
c.AddCommand(deprecated()...)

// Load plugins if any
if err := LoadPlugins(ctx, c); err != nil {
session := cliui.New(cliui.WithStdout(os.Stdout))
if err := LoadPlugins(ctx, c, session); err != nil {

Check warning on line 90 in ignite/cmd/cmd.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/cmd.go#L89-L90

Added lines #L89 - L90 were not covered by tests
return nil, nil, errors.Errorf("error while loading apps: %w", err)
}
return c, UnloadPlugins, nil
return c, func() {
UnloadPlugins()
session.End()
}, nil

Check warning on line 96 in ignite/cmd/cmd.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/cmd.go#L93-L96

Added lines #L93 - L96 were not covered by tests
}

func getVerbosity(cmd *cobra.Command) uilog.Verbosity {
Expand Down
22 changes: 7 additions & 15 deletions ignite/cmd/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

// LoadPlugins tries to load all the plugins found in configurations.
// If no configurations found, it returns w/o error.
func LoadPlugins(ctx context.Context, cmd *cobra.Command) error {
func LoadPlugins(ctx context.Context, cmd *cobra.Command, session *cliui.Session) error {

Check warning on line 34 in ignite/cmd/plugin.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/plugin.go#L34

Added line #L34 was not covered by tests
var (
rootCmd = cmd.Root()
pluginsConfigs []pluginsconfig.Plugin
Expand All @@ -53,9 +53,6 @@
return nil
}

session := cliui.New(cliui.WithStdout(os.Stdout))
defer session.End()

uniquePlugins := pluginsconfig.RemoveDuplicates(pluginsConfigs)
plugins, err = plugin.Load(ctx, uniquePlugins, plugin.CollectEvents(session.EventBus()))
if err != nil {
Expand Down Expand Up @@ -427,21 +424,17 @@
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
// update all plugins
err := plugin.Update(plugins...)
if err != nil {
if err := plugin.Update(plugins...); err != nil {

Check warning on line 427 in ignite/cmd/plugin.go

View workflow job for this annotation

GitHub Actions / Lint Go code

if-return: redundant if ...; err != nil check, just return error instead. (revive)

Check warning on line 427 in ignite/cmd/plugin.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/plugin.go#L427

Added line #L427 was not covered by tests
return err
}
cmd.Println("All apps updated.")
return nil
}
// find the plugin to update
for _, p := range plugins {
if p.Path == args[0] {
err := plugin.Update(p)
if err != nil {
if p.HasPath(args[0]) {
if err := plugin.Update(p); err != nil {

Check warning on line 435 in ignite/cmd/plugin.go

View workflow job for this annotation

GitHub Actions / Lint Go code

if-return: redundant if ...; err != nil check, just return error instead. (revive)

Check warning on line 435 in ignite/cmd/plugin.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/plugin.go#L434-L435

Added lines #L434 - L435 were not covered by tests
return err
}
cmd.Printf("App %q updated.\n", p.Path)
return nil
}
}
Expand Down Expand Up @@ -479,7 +472,7 @@
}

for _, p := range conf.Apps {
if p.Path == args[0] {
if p.HasPath(args[0]) {

Check warning on line 475 in ignite/cmd/plugin.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/plugin.go#L475

Added line #L475 was not covered by tests
return errors.Errorf("app %s is already installed", args[0])
}
}
Expand Down Expand Up @@ -507,7 +500,6 @@
p.With[kv[0]] = kv[1]
}

session.StartSpinner("Loading app")
plugins, err := plugin.Load(cmd.Context(), []pluginsconfig.Plugin{p}, pluginsOptions...)
if err != nil {
return err
Expand Down Expand Up @@ -562,7 +554,7 @@

removed := false
for i, cp := range conf.Apps {
if cp.Path == args[0] {
if cp.HasPath(args[0]) {

Check warning on line 557 in ignite/cmd/plugin.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/plugin.go#L557

Added line #L557 was not covered by tests
conf.Apps = append(conf.Apps[:i], conf.Apps[i+1:]...)
removed = true
break
Expand Down Expand Up @@ -648,7 +640,7 @@
ctx := cmd.Context()

for _, p := range plugins {
if p.Path == args[0] {
if p.HasPath(args[0]) {

Check warning on line 643 in ignite/cmd/plugin.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/plugin.go#L643

Added line #L643 was not covered by tests
manifest, err := p.Interface.Manifest(ctx)
if err != nil {
return errors.Errorf("error while loading app manifest: %w", err)
Expand Down
Loading