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 #3931

Merged
merged 6 commits 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 @@ To get started, create a blockchain:
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 {
return nil, nil, errors.Errorf("error while loading apps: %w", err)
}
return c, UnloadPlugins, nil
return c, func() {
UnloadPlugins()
session.End()
}, nil
}

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 {
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)
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)
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]) {
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]) {
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]) {
manifest, err := p.Interface.Manifest(ctx)
if err != nil {
return errors.Errorf("error while loading app manifest: %w", err)
Expand Down
Loading