From 82ec2611ebbe28fe58f0a1c8616bf63dae5178a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B3nimo=20Albi?= Date: Sat, 17 Feb 2024 00:25:25 +0100 Subject: [PATCH] feat: skip Ignite app load for some commands (#3972) * 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 --- changelog.md | 1 + ignite/cmd/cmd.go | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/changelog.md b/changelog.md index 573ddfa229..7239e22230 100644 --- a/changelog.md +++ b/changelog.md @@ -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 diff --git a/ignite/cmd/cmd.go b/ignite/cmd/cmd.go index 4cf17ade67..b33d5c985d 100644 --- a/ignite/cmd/cmd.go +++ b/ignite/cmd/cmd.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "slices" "sort" "strings" "time" @@ -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. @@ -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 {