Skip to content

Commit

Permalink
fix: fix app update command and duplicated apps (#3931)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani authored Feb 2, 2024
1 parent 9102e78 commit 65a4299
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
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 @@ var plugins []*plugin.Plugin

// 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 @@ func LoadPlugins(ctx context.Context, cmd *cobra.Command) error {
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 @@ If no path is specified all declared apps are updated.`,
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 @@ Respects key value pairs declared after the app path to be added to the generate
}

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 @@ Respects key value pairs declared after the app path to be added to the generate
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 @@ func NewAppUninstall() *cobra.Command {

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 @@ func NewAppDescribe() *cobra.Command {
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

0 comments on commit 65a4299

Please sign in to comment.