Skip to content

Commit

Permalink
feat: skip Ignite app load for some commands (#3972)
Browse files Browse the repository at this point in the history
* feat: skil Ignite app load for some commands

* chore: update changelog

* ci: fix linting issue

* fix: change app load check to validate level one commands only

All of the runnable commands that should not load Ignite apps are level
one commands (`ignite` command children), so a simple check is enough.

* chore: fix comment

---------

Co-authored-by: Danilo Pantani <[email protected]>
  • Loading branch information
jeronimoalbi and Pantani committed Feb 16, 2024
1 parent e6fd789 commit 82ec261
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- [#3959](https://github.com/ignite/cli/pull/3959) Remove app name prefix from the `.gitignore` file
- [#3962](https://github.com/ignite/cli/pull/3962) Rename all RPC endpoints and autocli commands generated for `map`/`list`/`single` types
- [#3972](https://github.com/ignite/cli/pull/3972) Skip Ignite app loading for some base commands that don't allow apps

### Fixes

Expand Down
9 changes: 9 additions & 0 deletions ignite/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"slices"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -39,6 +40,9 @@ const (
statusQuerying = "Querying..."
)

// List of CLI level one commands that should not load Ignite app instances.
var skipAppsLoadCommands = []string{"version", "help", "docs", "completion"}

// New creates a new root command for `Ignite CLI` with its sub commands.
// Returns the cobra.Command, a cleanup function and an error. The cleanup
// function must be invoked by the caller to clean eventual Ignite App instances.
Expand Down Expand Up @@ -85,6 +89,11 @@ To get started, create a blockchain:
)
c.AddCommand(deprecated()...)

// Don't load Ignite apps for level one commands that doesn't allow them
if len(os.Args) == 2 && slices.Contains(skipAppsLoadCommands, os.Args[1]) {
return c, func() {}, nil
}

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

0 comments on commit 82ec261

Please sign in to comment.