From 88ffe6208f81e158b096f8aeb78b8778075c875b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B3nimo=20Albi?= Date: Thu, 5 Oct 2023 12:27:07 +0200 Subject: [PATCH] refactor: rename CLI "plugin" command to "app" (#3662) * refactor: rename "plugin" to "app" * refactor: simplify code * chore: update changelog * tests: fixed unit tests * tests: fix integration tests * chore: change plugin template to use `app` as the type name * chore: update plugin code documentation to use "app" instead * tests: fixed service unit tests * chore: update comments * chore: fix typo * chore: improve command description * chore: restore plugin to test case names * chore: remove commented unit test code * chore: change app commands to properly set example command Co-authored-by: Julien Robert * chore: remove redundant plugin path check --- changelog.md | 1 + ignite/cmd/cmd.go | 8 +- ignite/cmd/plugin.go | 217 ++++++++++-------- ignite/cmd/plugin_default.go | 8 - ignite/cmd/plugin_test.go | 35 +-- ignite/config/plugins/config.go | 6 +- ignite/pkg/cliui/icons/icon.go | 9 +- ignite/services/plugin/cache.go | 2 +- ignite/services/plugin/interface.go | 78 ++++--- ignite/services/plugin/plugin.go | 21 +- ignite/services/plugin/plugin_test.go | 106 ++++----- ignite/services/plugin/scaffold.go | 2 +- ignite/services/plugin/template/main.go.plush | 14 +- integration/plugin/plugin_test.go | 20 +- 14 files changed, 261 insertions(+), 266 deletions(-) diff --git a/changelog.md b/changelog.md index d93a62dae8..6dc419c068 100644 --- a/changelog.md +++ b/changelog.md @@ -17,6 +17,7 @@ - [#3658](https://github.com/ignite/cli/pull/3658) Rename Marshaler to Codec in EncodingConfig - [#3653](https://github.com/ignite/cli/pull/3653) Add "app" extension to plugin binaries - [#3656](https://github.com/ignite/cli/pull/3656) Disable Go toolchain download +- [#3662](https://github.com/ignite/cli/pull/3662) Refactor CLI "plugin" command to "app" - [#3669](https://github.com/ignite/cli/pull/3669) Rename `plugins` config file to `igniteapps` ### Fixes diff --git a/ignite/cmd/cmd.go b/ignite/cmd/cmd.go index 311f8d5ea1..7549336770 100644 --- a/ignite/cmd/cmd.go +++ b/ignite/cmd/cmd.go @@ -39,8 +39,8 @@ const ( ) // 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 plugin instances. +// 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. func New(ctx context.Context) (*cobra.Command, func(), error) { cobra.EnableCommandSorting = false @@ -78,14 +78,14 @@ To get started, create a blockchain: NewTools(), NewDocs(), NewVersion(), - NewPlugin(), + NewApp(), NewDoctor(), ) c.AddCommand(deprecated()...) // Load plugins if any if err := LoadPlugins(ctx, c); err != nil { - return nil, nil, fmt.Errorf("error while loading plugins: %w", err) + return nil, nil, fmt.Errorf("error while loading apps: %w", err) } return c, UnloadPlugins, nil } diff --git a/ignite/cmd/plugin.go b/ignite/cmd/plugin.go index 64e77048fb..9c114149b3 100644 --- a/ignite/cmd/plugin.go +++ b/ignite/cmd/plugin.go @@ -76,7 +76,7 @@ func parseLocalPlugins(cmd *cobra.Command) (*pluginsconfig.Config, error) { _ = cmd wd, err := os.Getwd() if err != nil { - return nil, fmt.Errorf("parse local plugins: %w", err) + return nil, fmt.Errorf("parse local apps: %w", err) } if err := cosmosanalysis.IsChainPath(wd); err != nil { return nil, err @@ -165,11 +165,11 @@ func linkPluginHook(rootCmd *cobra.Command, p *plugin.Plugin, hook plugin.Hook) cmdPath := hook.PlaceHookOnFull() cmd := findCommandByPath(rootCmd, cmdPath) if cmd == nil { - p.Error = errors.Errorf("unable to find commandPath %q for plugin hook %q", cmdPath, hook.Name) + p.Error = errors.Errorf("unable to find command path %q for app hook %q", cmdPath, hook.Name) return } if !cmd.Runnable() { - p.Error = errors.Errorf("can't attach plugin hook %q to non executable command %q", hook.Name, hook.PlaceHookOn) + p.Error = errors.Errorf("can't attach app hook %q to non executable command %q", hook.Name, hook.PlaceHookOn) return } @@ -198,7 +198,7 @@ func linkPluginHook(rootCmd *cobra.Command, p *plugin.Plugin, hook plugin.Hook) } err := p.Interface.ExecuteHookPre(newExecutedHook(hook, cmd, args)) if err != nil { - return fmt.Errorf("plugin %q ExecuteHookPre() error: %w", p.Path, err) + return fmt.Errorf("app %q ExecuteHookPre() error: %w", p.Path, err) } return nil } @@ -212,7 +212,7 @@ func linkPluginHook(rootCmd *cobra.Command, p *plugin.Plugin, hook plugin.Hook) if err != nil { err := p.Interface.ExecuteHookCleanUp(newExecutedHook(hook, cmd, args)) if err != nil { - fmt.Printf("plugin %q ExecuteHookCleanUp() error: %v", p.Path, err) + fmt.Printf("app %q ExecuteHookCleanUp() error: %v", p.Path, err) } } return err @@ -229,7 +229,7 @@ func linkPluginHook(rootCmd *cobra.Command, p *plugin.Plugin, hook plugin.Hook) defer func() { err := p.Interface.ExecuteHookCleanUp(execHook) if err != nil { - fmt.Printf("plugin %q ExecuteHookCleanUp() error: %v", p.Path, err) + fmt.Printf("app %q ExecuteHookCleanUp() error: %v", p.Path, err) } }() @@ -243,7 +243,7 @@ func linkPluginHook(rootCmd *cobra.Command, p *plugin.Plugin, hook plugin.Hook) err := p.Interface.ExecuteHookPost(execHook) if err != nil { - return fmt.Errorf("plugin %q ExecuteHookPost() error : %w", p.Path, err) + return fmt.Errorf("app %q ExecuteHookPost() error : %w", p.Path, err) } return nil } @@ -267,11 +267,11 @@ func linkPluginCmd(rootCmd *cobra.Command, p *plugin.Plugin, pluginCmd plugin.Co cmdPath := pluginCmd.PlaceCommandUnderFull() cmd := findCommandByPath(rootCmd, cmdPath) if cmd == nil { - p.Error = errors.Errorf("unable to find commandPath %q for plugin %q", cmdPath, p.Path) + p.Error = errors.Errorf("unable to find command path %q for app %q", cmdPath, p.Path) return } if cmd.Runnable() { - p.Error = errors.Errorf("can't attach plugin command %q to runnable command %q", pluginCmd.Use, cmd.CommandPath()) + p.Error = errors.Errorf("can't attach app command %q to runnable command %q", pluginCmd.Use, cmd.CommandPath()) return } @@ -281,7 +281,7 @@ func linkPluginCmd(rootCmd *cobra.Command, p *plugin.Plugin, pluginCmd plugin.Co pluginCmdName := strings.Split(pluginCmd.Use, " ")[0] for _, cmd := range cmd.Commands() { if cmd.Name() == pluginCmdName { - p.Error = errors.Errorf("plugin command %q already exists in ignite's commands", pluginCmdName) + p.Error = errors.Errorf("app command %q already exists in Ignite's commands", pluginCmdName) return } } @@ -343,30 +343,30 @@ func findCommandByPath(cmd *cobra.Command, cmdPath string) *cobra.Command { return nil } -// NewPlugin returns a command that groups plugin related sub commands. -func NewPlugin() *cobra.Command { +// NewApp returns a command that groups Ignite App related sub commands. +func NewApp() *cobra.Command { c := &cobra.Command{ - Use: "plugin [command]", - Short: "Handle plugins", + Use: "app [command]", + Short: "Create and manage Ignite Apps", } c.AddCommand( - NewPluginList(), - NewPluginUpdate(), - NewPluginScaffold(), - NewPluginDescribe(), - NewPluginAdd(), - NewPluginRemove(), + NewAppList(), + NewAppUpdate(), + NewAppScaffold(), + NewAppDescribe(), + NewAppInstall(), + NewAppUninstall(), ) return c } -func NewPluginList() *cobra.Command { +func NewAppList() *cobra.Command { lstCmd := &cobra.Command{ Use: "list", - Short: "List declared plugins and status", - Long: "Prints status and information of declared plugins", + Short: "List installed apps", + Long: "Prints status and information of all installed Ignite Apps.", RunE: func(cmd *cobra.Command, args []string) error { s := cliui.New(cliui.WithStdout(os.Stdout)) return printPlugins(s) @@ -375,12 +375,15 @@ func NewPluginList() *cobra.Command { return lstCmd } -func NewPluginUpdate() *cobra.Command { +func NewAppUpdate() *cobra.Command { return &cobra.Command{ Use: "update [path]", - Short: "Update plugins", - Long: "Updates a plugin specified by path. If no path is specified all declared plugins are updated", - Args: cobra.MaximumNArgs(1), + Short: "Update app", + Long: `Updates an Ignite App specified by path. + +If no path is specified all declared apps are updated.`, + Example: "ignite app update github.com/org/my-app/", + Args: cobra.MaximumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { if len(args) == 0 { // update all plugins @@ -388,7 +391,7 @@ func NewPluginUpdate() *cobra.Command { if err != nil { return err } - fmt.Printf("All plugins updated.\n") + fmt.Printf("All apps updated.\n") return nil } // find the plugin to update @@ -398,25 +401,24 @@ func NewPluginUpdate() *cobra.Command { if err != nil { return err } - fmt.Printf("Plugin %q updated.\n", p.Path) + fmt.Printf("App %q updated.\n", p.Path) return nil } } - return errors.Errorf("Plugin %q not found", args[0]) + return errors.Errorf("App %q not found", args[0]) }, } } -func NewPluginAdd() *cobra.Command { +func NewAppInstall() *cobra.Command { cmdPluginAdd := &cobra.Command{ - Use: "add [path] [key=value]...", - Short: "Adds a plugin declaration to a plugin configuration", - Long: `Adds a plugin declaration to a plugin configuration. -Respects key value pairs declared after the plugin path to be added to the -generated configuration definition. -Example: - ignite plugin add github.com/org/my-plugin/ foo=bar baz=qux`, - Args: cobra.MinimumNArgs(1), + Use: "install [path] [key=value]...", + Short: "Install app", + Long: `Installs an Ignite App. + +Respects key value pairs declared after the app path to be added to the generated configuration definition.`, + Example: "ignite app install github.com/org/my-app/ foo=bar baz=qux", + Args: cobra.MinimumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { session := cliui.New(cliui.WithStdout(os.Stdout)) defer session.End() @@ -438,7 +440,7 @@ Example: for _, p := range conf.Apps { if p.Path == args[0] { - return fmt.Errorf("cannot add duplicate plugin %s", args[0]) + return fmt.Errorf("app %s is already installed", args[0]) } } @@ -465,7 +467,7 @@ Example: p.With[kv[0]] = kv[1] } - session.StartSpinner("Loading plugin") + session.StartSpinner("Loading app") plugins, err := plugin.Load(cmd.Context(), []pluginsconfig.Plugin{p}, pluginsOptions...) if err != nil { return err @@ -473,16 +475,16 @@ Example: defer plugins[0].KillClient() if plugins[0].Error != nil { - return fmt.Errorf("error while loading plugin %q: %w", args[0], plugins[0].Error) + return fmt.Errorf("error while loading app %q: %w", args[0], plugins[0].Error) } - session.Println("Done loading plugin") + session.Println(icons.OK, "Done loading apps") conf.Apps = append(conf.Apps, p) if err := conf.Save(); err != nil { return err } - session.Printf("🎉 %s added \n", args[0]) + session.Printf("%s Installed %s\n", icons.Tada, args[0]) return nil }, } @@ -492,11 +494,13 @@ Example: return cmdPluginAdd } -func NewPluginRemove() *cobra.Command { +func NewAppUninstall() *cobra.Command { cmdPluginRemove := &cobra.Command{ - Use: "remove [path]", + Use: "uninstall [path]", Aliases: []string{"rm"}, - Short: "Removes a plugin declaration from a chain's plugin configuration", + Short: "Uninstall app", + Long: "Uninstalls an Ignite App specified by path.", + Example: "ignite app uninstall github.com/org/my-app/", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { s := cliui.New(cliui.WithStdout(os.Stdout)) @@ -527,14 +531,14 @@ func NewPluginRemove() *cobra.Command { if !removed { // return if no matching plugin path found - return fmt.Errorf("plugin %s not found", args[0]) + return fmt.Errorf("app %s not found", args[0]) } if err := conf.Save(); err != nil { return err } - s.Printf("%s %s removed\n", icons.OK, args[0]) + s.Printf("%s %s uninstalled\n", icons.OK, args[0]) s.Printf("\t%s updated\n", conf.Path()) return nil @@ -546,12 +550,15 @@ func NewPluginRemove() *cobra.Command { return cmdPluginRemove } -func NewPluginScaffold() *cobra.Command { +func NewAppScaffold() *cobra.Command { return &cobra.Command{ - Use: "scaffold [github.com/org/repo]", - Short: "Scaffold a new plugin", - Long: "Scaffolds a new plugin in the current directory with the given repository path configured. A git repository will be created with the given module name, unless the current directory is already a git repository.", - Args: cobra.ExactArgs(1), + Use: "scaffold [name]", + Short: "Scaffold a new Ignite App", + Long: `Scaffolds a new Ignite App in the current directory. + +A git repository will be created with the given module name, unless the current directory is already a git repository.`, + Example: "ignite app scaffold github.com/org/my-app/", + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { session := cliui.New(cliui.StartSpinnerWithText(statusScaffolding)) defer session.End() @@ -569,19 +576,19 @@ func NewPluginScaffold() *cobra.Command { return err } - message := ` -⭐️ Successfully created a new plugin '%[1]s'. -👉 update plugin code at '%[2]s/main.go' + message := `⭐️ Successfully created a new Ignite App '%[1]s'. -👉 test plugin integration by adding the plugin to a chain's config: +👉 Update app code at '%[2]s/main.go' - ignite plugin add %[2]s +👉 Test Ignite App integration by installing the app within the chain directory: -Or to the global config: + ignite app install %[2]s - ignite plugin add -g %[2]s +Or globally: -👉 once the plugin is pushed to a repository, replace the local path by the repository path. + ignite app install -g %[2]s + +👉 Once the app is pushed to a repository, replace the local path by the repository path. ` session.Printf(message, moduleName, path) return nil @@ -589,12 +596,13 @@ Or to the global config: } } -func NewPluginDescribe() *cobra.Command { +func NewAppDescribe() *cobra.Command { return &cobra.Command{ - Use: "describe [path]", - Short: "Output information about the a registered plugin", - Long: "Output information about a registered plugins commands and hooks.", - Args: cobra.ExactArgs(1), + Use: "describe [path]", + Short: "Print information about installed apps", + Long: "Print information about an installed Ignite App commands and hooks.", + Example: "ignite app describe github.com/org/my-app/", + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { s := cliui.New(cliui.WithStdout(os.Stdout)) @@ -602,18 +610,24 @@ func NewPluginDescribe() *cobra.Command { if p.Path == args[0] { manifest, err := p.Interface.Manifest() if err != nil { - return fmt.Errorf("error while loading plugin manifest: %w", err) + return fmt.Errorf("error while loading app manifest: %w", err) } - s.Printf("Plugin '%s':\n", args[0]) - s.Printf("%s %d Command(s):\n", icons.Command, len(manifest.Commands)) - for i, c := range manifest.Commands { - cmdPath := fmt.Sprintf("%s %s", c.PlaceCommandUnderFull(), c.Use) - s.Printf("\t%d) '%s'\n", i+1, cmdPath) + + if len(manifest.Commands) > 0 { + s.Println("Commands:") + for i, c := range manifest.Commands { + cmdPath := fmt.Sprintf("%s %s", c.PlaceCommandUnderFull(), c.Use) + s.Printf(" %d) %s\n", i+1, cmdPath) + } } - s.Printf("%s %d Hook(s):\n", icons.Hook, len(manifest.Hooks)) - for i, h := range manifest.Hooks { - s.Printf("\t%d) '%s' on command '%s'\n", i+1, h.Name, h.PlaceHookOnFull()) + + if len(manifest.Hooks) > 0 { + s.Println("Hooks:") + for i, h := range manifest.Hooks { + s.Printf(" %d) '%s' on command '%s'\n", i+1, h.Name, h.PlaceHookOnFull()) + } } + break } } @@ -623,35 +637,34 @@ func NewPluginDescribe() *cobra.Command { } } +func getPluginLocationName(p *plugin.Plugin) string { + if p.IsGlobal() { + return "global" + } + return "local" +} + +func getPluginStatus(p *plugin.Plugin) string { + if p.Error != nil { + return fmt.Sprintf("%s Error: %v", icons.NotOK, p.Error) + } + + _, err := p.Interface.Manifest() + if err != nil { + return fmt.Sprintf("%s Error: Manifest() returned %v", icons.NotOK, err) + } + + return fmt.Sprintf("%s Loaded", icons.OK) +} + func printPlugins(session *cliui.Session) error { - var ( - entries [][]string - buildStatus = func(p *plugin.Plugin) string { - if p.Error != nil { - return fmt.Sprintf("%s Error: %v", icons.NotOK, p.Error) - } - manifest, err := p.Interface.Manifest() - if err != nil { - return fmt.Sprintf("%s Error: Manifest() returned %v", icons.NotOK, err) - } - var ( - hookCount = len(manifest.Hooks) - cmdCount = len(manifest.Commands) - ) - return fmt.Sprintf("%s Loaded: %s %d %s%d ", icons.OK, icons.Command, cmdCount, icons.Hook, hookCount) - } - installedStatus = func(p *plugin.Plugin) string { - if p.IsGlobal() { - return "global" - } - return "local" - } - ) + var entries [][]string for _, p := range plugins { - entries = append(entries, []string{p.Path, buildStatus(p), installedStatus(p)}) + entries = append(entries, []string{p.Path, getPluginLocationName(p), getPluginStatus(p)}) } - if err := session.PrintTable([]string{"Path", "Status", "Config"}, entries...); err != nil { - return fmt.Errorf("error while printing plugins: %w", err) + + if err := session.PrintTable([]string{"Path", "Config", "Status"}, entries...); err != nil { + return fmt.Errorf("error while printing apps: %w", err) } return nil } diff --git a/ignite/cmd/plugin_default.go b/ignite/cmd/plugin_default.go index a7a2424197..6d9b995704 100644 --- a/ignite/cmd/plugin_default.go +++ b/ignite/cmd/plugin_default.go @@ -1,8 +1,6 @@ package ignitecmd import ( - "fmt" - "github.com/spf13/cobra" pluginsconfig "github.com/ignite/cli/ignite/config/plugins" @@ -63,12 +61,6 @@ func newPluginInstallCmd(dp defaultPlugin) *cobra.Command { if err != nil { return err } - if cfg.HasPlugin(dp.path) { - // plugin already declared in global plugins, this shouldn't happen - // because this is actually why this command has been added, so let's - // break violently - panic(fmt.Sprintf("plugin %q unexpected in global config", dp.path)) - } // add plugin to config pluginCfg := pluginsconfig.Plugin{ diff --git a/ignite/cmd/plugin_test.go b/ignite/cmd/plugin_test.go index 6fe44382a2..baded90f0a 100644 --- a/ignite/cmd/plugin_test.go +++ b/ignite/cmd/plugin_test.go @@ -167,7 +167,7 @@ ignite nil, ) }, - expectedError: `can't attach plugin command "foo" to runnable command "ignite scaffold chain"`, + expectedError: `can't attach app command "foo" to runnable command "ignite scaffold chain"`, }, { name: "fail: link to unknown command", @@ -183,7 +183,7 @@ ignite nil, ) }, - expectedError: `unable to find commandPath "ignite unknown" for plugin "foo"`, + expectedError: `unable to find command path "ignite unknown" for app "foo"`, }, { name: "fail: plugin name exists in legacy commands", @@ -198,7 +198,7 @@ ignite nil, ) }, - expectedError: `plugin command "scaffold" already exists in ignite's commands`, + expectedError: `app command "scaffold" already exists in Ignite's commands`, }, { name: "fail: plugin name with args exists in legacy commands", @@ -213,7 +213,7 @@ ignite nil, ) }, - expectedError: `plugin command "scaffold" already exists in ignite's commands`, + expectedError: `app command "scaffold" already exists in Ignite's commands`, }, { name: "fail: plugin name exists in legacy sub commands", @@ -229,7 +229,7 @@ ignite nil, ) }, - expectedError: `plugin command "chain" already exists in ignite's commands`, + expectedError: `app command "chain" already exists in Ignite's commands`, }, { name: "ok: link multiple at root", @@ -412,27 +412,6 @@ func TestLinkPluginHooks(t *testing.T) { expectedError string setup func(*testing.T, *mocks.PluginInterface) }{ - // TODO(tb): commented because linkPluginCmds is not invoked in this test, - // so it's not possible to assert that a hook can't be placed on a plugin - // command. - /* - { - name: "fail: hook plugin command", - setup: func(t *testing.T, p*mocks.PluginInterface) { - p.EXPECT().Manifest().Return(plugin.Manifest{Commands:[]plugin.Command{{Use: "test-plugin"}}, nil) - p.EXPECT().Manifest().Return(plugin.Manifest{ - []plugin.Hook{ - { - Name: "test-hook", - PlaceHookOn: "ignite test-plugin", - }, - }, - nil, - ) - }, - expectedError: `unable to find commandPath "ignite test-plugin" for plugin hook "test-hook"`, - }, - */ { name: "fail: command not runnable", setup: func(t *testing.T, p *mocks.PluginInterface) { @@ -447,7 +426,7 @@ func TestLinkPluginHooks(t *testing.T) { nil, ) }, - expectedError: `can't attach plugin hook "test-hook" to non executable command "ignite scaffold"`, + expectedError: `can't attach app hook "test-hook" to non executable command "ignite scaffold"`, }, { name: "fail: command doesn't exists", @@ -463,7 +442,7 @@ func TestLinkPluginHooks(t *testing.T) { nil, ) }, - expectedError: `unable to find commandPath "ignite chain" for plugin hook "test-hook"`, + expectedError: `unable to find command path "ignite chain" for app hook "test-hook"`, }, { name: "ok: single hook", diff --git a/ignite/config/plugins/config.go b/ignite/config/plugins/config.go index 4c5bf2e05b..8b386a2d9b 100644 --- a/ignite/config/plugins/config.go +++ b/ignite/config/plugins/config.go @@ -13,7 +13,6 @@ import ( ) type Config struct { - // path to the config file path string // Apps holds the list of installed Ignite Apps. @@ -89,9 +88,8 @@ func (p Plugin) IsLocalPath() bool { } // HasPath verifies if a plugin has the given path regardless of version. -// Example: -// github.com/foo/bar@v1 and github.com/foo/bar@v2 have the same path so "true" -// will be returned. +// For example github.com/foo/bar@v1 and github.com/foo/bar@v2 have the +// same path so "true" will be returned. func (p Plugin) HasPath(path string) bool { if path == "" { return false diff --git a/ignite/pkg/cliui/icons/icon.go b/ignite/pkg/cliui/icons/icon.go index 7a9d5373a9..75495e9753 100644 --- a/ignite/pkg/cliui/icons/icon.go +++ b/ignite/pkg/cliui/icons/icon.go @@ -5,11 +5,10 @@ import ( ) var ( - Earth = "🌍" - CD = "💿" - User = "👤" - Command = "❯⎯" - Hook = "🪝" + Earth = "🌍" + CD = "💿" + User = "👤" + Tada = "🎉" // OK is an OK mark. OK = colors.SprintFunc(colors.Green)("✔") diff --git a/ignite/services/plugin/cache.go b/ignite/services/plugin/cache.go index 6d38303d40..a0832da6ce 100644 --- a/ignite/services/plugin/cache.go +++ b/ignite/services/plugin/cache.go @@ -28,7 +28,7 @@ func writeConfigCache(pluginPath string, conf hplugin.ReattachConfig) error { return fmt.Errorf("provided path is invalid: %s", pluginPath) } if conf.Addr == nil { - return fmt.Errorf("plugin Address info cannot be empty") + return fmt.Errorf("app Address info cannot be empty") } cache, err := newCache() if err != nil { diff --git a/ignite/services/plugin/interface.go b/ignite/services/plugin/interface.go index c200f29cf6..b423f8485e 100644 --- a/ignite/services/plugin/interface.go +++ b/ignite/services/plugin/interface.go @@ -20,14 +20,14 @@ func init() { gob.Register(ExecutedHook{}) } -// An ignite plugin must implements the Plugin interface. +// Interface defines the interface that all Ignite App must implement. // //go:generate mockery --srcpkg . --name Interface --structname PluginInterface --filename interface.go --with-expecter type Interface interface { - // Manifest declares the plugin's Command(s) and Hook(s). + // Manifest declares the app's Command(s) and Hook(s). Manifest() (Manifest, error) - // Execute will be invoked by ignite when a plugin Command is executed. + // Execute will be invoked by ignite when an app Command is executed. // It is global for all commands declared in Manifest, if you have declared // multiple commands, use cmd.Path to distinguish them. Execute(cmd ExecutedCommand) error @@ -37,11 +37,13 @@ type Interface interface { // It is global for all hooks declared in Manifest, if you have declared // multiple hooks, use hook.Name to distinguish them. ExecuteHookPre(hook ExecutedHook) error + // ExecuteHookPost is invoked by ignite when a command specified by the hook // path is invoked. // It is global for all hooks declared in Manifest, if you have declared // multiple hooks, use hook.Name to distinguish them. ExecuteHookPost(hook ExecutedHook) error + // ExecuteHookCleanUp is invoked by ignite when a command specified by the // hook path is invoked. Unlike ExecuteHookPost, it is invoked regardless of // execution status of the command and hooks. @@ -50,28 +52,32 @@ type Interface interface { ExecuteHookCleanUp(hook ExecutedHook) error } -// Manifest represents the plugin behavior. +// Manifest represents the Ignite App behavior. type Manifest struct { Name string + // Commands contains the commands that will be added to the list of ignite // commands. Each commands are independent, for nested commands use the // inner Commands field. Commands []Command + // Hooks contains the hooks that will be attached to the existing ignite // commands. Hooks []Hook - // SharedHost enables sharing a single plugin server across all running instances - // of a plugin. Useful if a plugin adds or extends long running commands + + // SharedHost enables sharing a single app server across all running instances + // of an app. Useful if an app adds or extends long running commands // - // Example: if a plugin defines a hook on `ignite chain serve`, a plugin server is instanciated + // Example: if an app defines a hook on `ignite chain serve`, a server is instanciated // when the command is run. Now if you want to interact with that instance from commands - // defined in that plugin, you need to enable `SharedHost`, or else the commands will just - // instantiate separate plugin servers. + // defined in that app, you need to enable `SharedHost`, or else the commands will just + // instantiate separate app servers. // - // When enabled, all plugins of the same `Path` loaded from the same configuration will - // attach it's rpc client to a an existing rpc server. + // When enabled, all apps of the same `Path` loaded from the same configuration will + // attach it's RPC client to a an existing RPC server. // - // If a plugin instance has no other running plugin servers, it will create one and it will be the host. + // If an app instance has no other running app servers, it will create one and it + // will be the host. SharedHost bool `yaml:"shared_host"` } @@ -96,31 +102,38 @@ func convertCobraCommand(c *cobra.Command, placeCommandUnder string) Command { return cmd } -// Command represents a plugin command. +// Command represents an app command. type Command struct { // Same as cobra.Command.Use Use string + // Same as cobra.Command.Aliases Aliases []string + // Same as cobra.Command.Short Short string + // Same as cobra.Command.Long Long string + // Same as cobra.Command.Hidden Hidden bool + // Flags holds the list of command flags Flags []Flag + // PlaceCommandUnder indicates where the command should be placed. // For instance `ignite scaffold` will place the command at the // `scaffold` command. // An empty value is interpreted as `ignite` (==root). PlaceCommandUnder string + // List of sub commands Commands []Command } -// PlaceCommandUnderFull returns a normalized p.PlaceCommandUnder, by adding -// the `ignite ` prefix if not present. +// PlaceCommandUnderFull returns a normalized p.PlaceCommandUnder, +// by adding the `ignite ` prefix if not present. func (c Command) PlaceCommandUnderFull() string { return commandFull(c.PlaceCommandUnder) } @@ -133,8 +146,7 @@ func commandFull(cmdPath string) string { return strings.TrimSpace(cmdPath) } -// ToCobraCommand turns Command into a cobra.Command so it can be added to a -// parent command. +// ToCobraCommand turns Command into a cobra.Command so it can be added to a parent command. func (c Command) ToCobraCommand() (*cobra.Command, error) { cmd := &cobra.Command{ Use: c.Use, @@ -152,11 +164,12 @@ func (c Command) ToCobraCommand() (*cobra.Command, error) { return cmd, nil } -// Hook represents a user defined action within a plugin. +// Hook represents a user defined action within an app. type Hook struct { // Name identifies the hook for the client to invoke the correct hook // must be unique Name string + // PlaceHookOn indicates the command to register the hooks for PlaceHookOn string } @@ -167,24 +180,28 @@ func (h Hook) PlaceHookOnFull() string { return commandFull(h.PlaceHookOn) } -// ExecutedCommand represents a plugin command under execution. +// ExecutedCommand represents an app command under execution. type ExecutedCommand struct { // Use is copied from Command.Use Use string + // Path contains the command path, e.g. `ignite scaffold foo` Path string + // Args are the command arguments Args []string + // Full list of args taken from os.Args OSArgs []string - // With contains the plugin config parameters + + // With contains the app config parameters With map[string]string flags *pflag.FlagSet pflags *pflag.FlagSet } -// ExecutedHook represents a plugin hook under execution. +// ExecutedHook represents an app hook under execution. type ExecutedHook struct { // ExecutedCommand gives access to the command attached by the hook. ExecutedCommand ExecutedCommand @@ -210,7 +227,7 @@ func (c *ExecutedCommand) PersistentFlags() *pflag.FlagSet { } // SetFlags set the flags. -// As a plugin developer, you probably don't need to use it. +// As an app developer, you probably don't need to use it. func (c *ExecutedCommand) SetFlags(cmd *cobra.Command) { c.flags = cmd.Flags() c.pflags = cmd.PersistentFlags() @@ -224,8 +241,8 @@ type Flag struct { DefValue string // default value (as text); for usage message Type FlagType Value string - // Persistent indicates wether or not the flag is propagated on children - // commands + + // Persistent indicates wether or not the flag is propagated on children commands Persistent bool } @@ -234,7 +251,7 @@ type FlagType string const ( // NOTE(tb): we declare only the main used cobra flag types for simplicity - // If a plugin receives an unhandled type, it will output an error. + // If an app receives an unhandled type, it will output an error. FlagTypeString FlagType = "string" FlagTypeInt FlagType = "int" FlagTypeUint FlagType = "uint" @@ -365,8 +382,8 @@ func (c *ExecutedCommand) GobDecode(bz []byte) error { } // handshakeConfigs are used to just do a basic handshake between -// a plugin and host. If the handshake fails, a user friendly error is shown. -// This prevents users from executing bad plugins or executing a plugin +// an app and host. If the handshake fails, a user friendly error is shown. +// This prevents users from executing bad apps or executing an app // directory. It is a UX feature, not a security feature. var handshakeConfig = plugin.HandshakeConfig{ ProtocolVersion: 1, @@ -419,7 +436,6 @@ func (g *InterfaceRPC) ExecuteHookCleanUp(hook ExecutedHook) error { // InterfaceRPCServer is the RPC server that InterfaceRPC talks to, conforming to // the requirements of net/rpc. type InterfaceRPCServer struct { - // This is the real implementation Impl Interface } @@ -445,18 +461,14 @@ func (s *InterfaceRPCServer) ExecuteHookCleanUp(args map[string]interface{}, _ * return s.Impl.ExecuteHookCleanUp(args["executedHook"].(ExecutedHook)) } -// This is the implementation of plugin.Interface so we can serve/consume this +// InterfacePlugin is the implementation of Interface. // // This has two methods: Server must return an RPC server for this plugin // type. We construct a InterfaceRPCServer for this. // // Client must return an implementation of our interface that communicates // over an RPC client. We return InterfaceRPC for this. -// -// Ignore MuxBroker. That is used to create more multiplexed streams on our -// plugin connection and is a more advanced use case. type InterfacePlugin struct { - // Impl Injection Impl Interface } diff --git a/ignite/services/plugin/plugin.go b/ignite/services/plugin/plugin.go index 28091675a6..0081c381c1 100644 --- a/ignite/services/plugin/plugin.go +++ b/ignite/services/plugin/plugin.go @@ -20,6 +20,7 @@ import ( "github.com/ignite/cli/ignite/config" pluginsconfig "github.com/ignite/cli/ignite/config/plugins" + "github.com/ignite/cli/ignite/pkg/cliui/icons" "github.com/ignite/cli/ignite/pkg/env" "github.com/ignite/cli/ignite/pkg/events" "github.com/ignite/cli/ignite/pkg/gocmd" @@ -117,7 +118,7 @@ func newPlugin(pluginsDir string, cp pluginsconfig.Plugin, options ...Option) *P pluginPath = cp.Path ) if pluginPath == "" { - p.Error = errors.Errorf(`missing plugin property "path"`) + p.Error = errors.Errorf(`missing app property "path"`) return p } @@ -130,11 +131,11 @@ func newPlugin(pluginsDir string, cp pluginsconfig.Plugin, options ...Option) *P // This is a local plugin, check if the file exists st, err := os.Stat(pluginPath) if err != nil { - p.Error = errors.Wrapf(err, "local plugin path %q not found", pluginPath) + p.Error = errors.Wrapf(err, "local app path %q not found", pluginPath) return p } if !st.IsDir() { - p.Error = errors.Errorf("local plugin path %q is not a dir", pluginPath) + p.Error = errors.Errorf("local app path %q is not a directory", pluginPath) return p } p.srcPath = pluginPath @@ -149,7 +150,7 @@ func newPlugin(pluginsDir string, cp pluginsconfig.Plugin, options ...Option) *P } parts := strings.Split(pluginPath, "/") if len(parts) < 3 { - p.Error = errors.Errorf("plugin path %q is not a valid repository URL", pluginPath) + p.Error = errors.Errorf("app path %q is not a valid repository URL", pluginPath) return p } p.repoPath = path.Join(parts[:3]...) @@ -239,7 +240,7 @@ func (p *Plugin) load(ctx context.Context) { logLevel = hclog.Trace } logger := hclog.New(&hclog.LoggerOptions{ - Name: fmt.Sprintf("plugin %s", p.Path), + Name: fmt.Sprintf("app %s", p.Path), Output: os.Stderr, Level: logLevel, }) @@ -321,8 +322,8 @@ func (p *Plugin) fetch() { if p.Error != nil { return } - p.ev.Send(fmt.Sprintf("Fetching plugin %q", p.cloneURL), events.ProgressStart()) - defer p.ev.Send(fmt.Sprintf("Plugin fetched %q", p.cloneURL), events.ProgressFinish()) + p.ev.Send(fmt.Sprintf("Fetching app %q", p.cloneURL), events.ProgressStart()) + defer p.ev.Send(fmt.Sprintf("%s App fetched %q", icons.OK, p.cloneURL), events.ProgressFinish()) urlref := strings.Join([]string{p.cloneURL, p.reference}, "@") err := xgit.Clone(context.Background(), urlref, p.cloneDir) @@ -336,8 +337,8 @@ func (p *Plugin) build(ctx context.Context) { if p.Error != nil { return } - p.ev.Send(fmt.Sprintf("Building plugin %q", p.Path), events.ProgressStart()) - defer p.ev.Send(fmt.Sprintf("Plugin built %q", p.Path), events.ProgressFinish()) + p.ev.Send(fmt.Sprintf("Building app %q", p.Path), events.ProgressStart()) + defer p.ev.Send(fmt.Sprintf("%s App built %q", icons.OK, p.Path), events.ProgressFinish()) if err := gocmd.ModTidy(ctx, p.srcPath); err != nil { p.Error = errors.Wrapf(err, "go mod tidy") @@ -391,7 +392,7 @@ func (p *Plugin) outdatedBinary() bool { return nil }) if err != nil { - fmt.Printf("error while walking plugin source path %q\n", p.srcPath) + fmt.Printf("error while walking app source path %q\n", p.srcPath) return false } return mostRecent.After(binaryTime) diff --git a/ignite/services/plugin/plugin_test.go b/ignite/services/plugin/plugin_test.go index 08d59f91b6..da3795b913 100644 --- a/ignite/services/plugin/plugin_test.go +++ b/ignite/services/plugin/plugin_test.go @@ -34,21 +34,21 @@ func TestNewPlugin(t *testing.T) { { name: "fail: empty path", expectedPlugin: Plugin{ - Error: errors.Errorf(`missing plugin property "path"`), + Error: errors.Errorf(`missing app property "path"`), }, }, { name: "fail: local plugin doesnt exists", - pluginCfg: pluginsconfig.Plugin{Path: "/xxx/yyy/plugin"}, + pluginCfg: pluginsconfig.Plugin{Path: "/xxx/yyy/app"}, expectedPlugin: Plugin{ - Error: errors.Errorf(`local plugin path "/xxx/yyy/plugin" not found`), + Error: errors.Errorf(`local app path "/xxx/yyy/app" not found`), }, }, { - name: "fail: local plugin is not a dir", + name: "fail: local plugin is not a directory", pluginCfg: pluginsconfig.Plugin{Path: path.Join(wd, "testdata/fakebin")}, expectedPlugin: Plugin{ - Error: errors.Errorf(fmt.Sprintf("local plugin path %q is not a dir", path.Join(wd, "testdata/fakebin"))), + Error: errors.Errorf(fmt.Sprintf("local app path %q is not a directory", path.Join(wd, "testdata/fakebin"))), }, }, { @@ -63,85 +63,85 @@ func TestNewPlugin(t *testing.T) { name: "fail: remote plugin with only domain", pluginCfg: pluginsconfig.Plugin{Path: "github.com"}, expectedPlugin: Plugin{ - Error: errors.Errorf(`plugin path "github.com" is not a valid repository URL`), + Error: errors.Errorf(`app path "github.com" is not a valid repository URL`), }, }, { name: "fail: remote plugin with incomplete URL", pluginCfg: pluginsconfig.Plugin{Path: "github.com/ignite"}, expectedPlugin: Plugin{ - Error: errors.Errorf(`plugin path "github.com/ignite" is not a valid repository URL`), + Error: errors.Errorf(`app path "github.com/ignite" is not a valid repository URL`), }, }, { - name: "ok: remote plugin", - pluginCfg: pluginsconfig.Plugin{Path: "github.com/ignite/plugin"}, + name: "ok: remote app", + pluginCfg: pluginsconfig.Plugin{Path: "github.com/ignite/app"}, expectedPlugin: Plugin{ - repoPath: "github.com/ignite/plugin", - cloneURL: "https://github.com/ignite/plugin", - cloneDir: ".ignite/apps/github.com/ignite/plugin", + repoPath: "github.com/ignite/app", + cloneURL: "https://github.com/ignite/app", + cloneDir: ".ignite/apps/github.com/ignite/app", reference: "", - srcPath: ".ignite/apps/github.com/ignite/plugin", - name: "plugin", + srcPath: ".ignite/apps/github.com/ignite/app", + name: "app", }, }, { name: "ok: remote plugin with @ref", - pluginCfg: pluginsconfig.Plugin{Path: "github.com/ignite/plugin@develop"}, + pluginCfg: pluginsconfig.Plugin{Path: "github.com/ignite/app@develop"}, expectedPlugin: Plugin{ - repoPath: "github.com/ignite/plugin@develop", - cloneURL: "https://github.com/ignite/plugin", - cloneDir: ".ignite/apps/github.com/ignite/plugin-develop", + repoPath: "github.com/ignite/app@develop", + cloneURL: "https://github.com/ignite/app", + cloneDir: ".ignite/apps/github.com/ignite/app-develop", reference: "develop", - srcPath: ".ignite/apps/github.com/ignite/plugin-develop", - name: "plugin", + srcPath: ".ignite/apps/github.com/ignite/app-develop", + name: "app", }, }, { name: "ok: remote plugin with @ref containing slash", - pluginCfg: pluginsconfig.Plugin{Path: "github.com/ignite/plugin@package/v1.0.0"}, + pluginCfg: pluginsconfig.Plugin{Path: "github.com/ignite/app@package/v1.0.0"}, expectedPlugin: Plugin{ - repoPath: "github.com/ignite/plugin@package/v1.0.0", - cloneURL: "https://github.com/ignite/plugin", - cloneDir: ".ignite/apps/github.com/ignite/plugin-package-v1.0.0", + repoPath: "github.com/ignite/app@package/v1.0.0", + cloneURL: "https://github.com/ignite/app", + cloneDir: ".ignite/apps/github.com/ignite/app-package-v1.0.0", reference: "package/v1.0.0", - srcPath: ".ignite/apps/github.com/ignite/plugin-package-v1.0.0", - name: "plugin", + srcPath: ".ignite/apps/github.com/ignite/app-package-v1.0.0", + name: "app", }, }, { name: "ok: remote plugin with subpath", - pluginCfg: pluginsconfig.Plugin{Path: "github.com/ignite/plugin/plugin1"}, + pluginCfg: pluginsconfig.Plugin{Path: "github.com/ignite/app/plugin1"}, expectedPlugin: Plugin{ - repoPath: "github.com/ignite/plugin", - cloneURL: "https://github.com/ignite/plugin", - cloneDir: ".ignite/apps/github.com/ignite/plugin", + repoPath: "github.com/ignite/app", + cloneURL: "https://github.com/ignite/app", + cloneDir: ".ignite/apps/github.com/ignite/app", reference: "", - srcPath: ".ignite/apps/github.com/ignite/plugin/plugin1", + srcPath: ".ignite/apps/github.com/ignite/app/plugin1", name: "plugin1", }, }, { name: "ok: remote plugin with subpath and @ref", - pluginCfg: pluginsconfig.Plugin{Path: "github.com/ignite/plugin/plugin1@develop"}, + pluginCfg: pluginsconfig.Plugin{Path: "github.com/ignite/app/plugin1@develop"}, expectedPlugin: Plugin{ - repoPath: "github.com/ignite/plugin@develop", - cloneURL: "https://github.com/ignite/plugin", - cloneDir: ".ignite/apps/github.com/ignite/plugin-develop", + repoPath: "github.com/ignite/app@develop", + cloneURL: "https://github.com/ignite/app", + cloneDir: ".ignite/apps/github.com/ignite/app-develop", reference: "develop", - srcPath: ".ignite/apps/github.com/ignite/plugin-develop/plugin1", + srcPath: ".ignite/apps/github.com/ignite/app-develop/plugin1", name: "plugin1", }, }, { name: "ok: remote plugin with subpath and @ref containing slash", - pluginCfg: pluginsconfig.Plugin{Path: "github.com/ignite/plugin/plugin1@package/v1.0.0"}, + pluginCfg: pluginsconfig.Plugin{Path: "github.com/ignite/app/plugin1@package/v1.0.0"}, expectedPlugin: Plugin{ - repoPath: "github.com/ignite/plugin@package/v1.0.0", - cloneURL: "https://github.com/ignite/plugin", - cloneDir: ".ignite/apps/github.com/ignite/plugin-package-v1.0.0", + repoPath: "github.com/ignite/app@package/v1.0.0", + cloneURL: "https://github.com/ignite/app", + cloneDir: ".ignite/apps/github.com/ignite/app-package-v1.0.0", reference: "package/v1.0.0", - srcPath: ".ignite/apps/github.com/ignite/plugin-package-v1.0.0/plugin1", + srcPath: ".ignite/apps/github.com/ignite/app-package-v1.0.0/plugin1", name: "plugin1", }, }, @@ -241,7 +241,7 @@ func TestPluginLoad(t *testing.T) { repoPath: "/xxxx/yyyy", cloneURL: "/xxxx/yyyy", cloneDir: cloneDir, - srcPath: path.Join(cloneDir, "plugin"), + srcPath: path.Join(cloneDir, "app"), } }, expectedError: `cloning "/xxxx/yyyy": repository not found`, @@ -410,10 +410,10 @@ func TestPluginLoadSharedHost(t *testing.T) { for i := len(plugins) - 1; i >= 0; i-- { plugins[i].KillClient() if tt.sharesHost && i > 0 { - assert.False(plugins[i].client.Exited(), "non host plugin can't kill host plugin") - assert.True(checkConfCache(plugins[i].Path), "non host plugin doesn't remove config cache when killed") + assert.False(plugins[i].client.Exited(), "non host app can't kill host app") + assert.True(checkConfCache(plugins[i].Path), "non host app doesn't remove config cache when killed") } else { - assert.True(plugins[i].client.Exited(), "plugin should be killed") + assert.True(plugins[i].client.Exited(), "app should be killed") } assert.False(plugins[i].isHost, "killed plugins are no longer host") } @@ -426,21 +426,21 @@ func TestPluginLoadSharedHost(t *testing.T) { assert.True(checkConfCache(plugins[i].Path), "sharedHost must have a cache entry") if i == 0 { // first plugin is the host - assert.True(plugins[i].isHost, "first plugin is the host") + assert.True(plugins[i].isHost, "first app is the host") // Assert reattach config has been saved hostConf = plugins[i].client.ReattachConfig() ref, err := readConfigCache(plugins[i].Path) if assert.NoError(err) { - assert.Equal(hostConf, &ref, "wrong cache entry for plugin host") + assert.Equal(hostConf, &ref, "wrong cache entry for app host") } } else { // plugins after first aren't host - assert.False(plugins[i].isHost, "plugin %d can't be host", i) - assert.Equal(hostConf, plugins[i].client.ReattachConfig(), "ReattachConfig different from host plugin") + assert.False(plugins[i].isHost, "app %d can't be host", i) + assert.Equal(hostConf, plugins[i].client.ReattachConfig(), "ReattachConfig different from host app") } } else { - assert.False(plugins[i].isHost, "plugin %d can't be host if sharedHost is disabled", i) - assert.False(checkConfCache(plugins[i].Path), "plugin %d can't have a cache entry if sharedHost is disabled", i) + assert.False(plugins[i].isHost, "app %d can't be host if sharedHost is disabled", i) + assert.False(checkConfCache(plugins[i].Path), "app %d can't have a cache entry if sharedHost is disabled", i) } } }) @@ -454,7 +454,7 @@ func TestPluginClean(t *testing.T) { expectRemove bool }{ { - name: "dont clean local plugin", + name: "dont clean local app", plugin: &Plugin{ Plugin: pluginsconfig.Plugin{Path: "/local"}, }, @@ -466,7 +466,7 @@ func TestPluginClean(t *testing.T) { { name: "ok", plugin: &Plugin{ - cloneURL: "https://github.com/ignite/plugin", + cloneURL: "https://github.com/ignite/app", }, expectRemove: true, }, diff --git a/ignite/services/plugin/scaffold.go b/ignite/services/plugin/scaffold.go index e8bbc2f651..ff2a7fe093 100644 --- a/ignite/services/plugin/scaffold.go +++ b/ignite/services/plugin/scaffold.go @@ -32,7 +32,7 @@ func Scaffold(dir, moduleName string, sharedHost bool) (string, error) { ) if _, err := os.Stat(finalDir); err == nil { // finalDir already exists, don't overwrite stuff - return "", errors.Errorf("dir %q already exists, abort scaffolding", finalDir) + return "", errors.Errorf("directory %q already exists, abort scaffolding", finalDir) } if err := g.Box(template); err != nil { return "", errors.WithStack(err) diff --git a/ignite/services/plugin/template/main.go.plush b/ignite/services/plugin/template/main.go.plush index dbdbcd3e63..077f10f250 100644 --- a/ignite/services/plugin/template/main.go.plush +++ b/ignite/services/plugin/template/main.go.plush @@ -17,9 +17,9 @@ func init() { gob.Register(plugin.ExecutedHook{}) } -type p struct{} +type app struct{} -func (p) Manifest() (plugin.Manifest, error) { +func (app) Manifest() (plugin.Manifest, error) { return plugin.Manifest{ Name: "<%= Name %>", // Add commands here @@ -49,7 +49,7 @@ func (p) Manifest() (plugin.Manifest, error) { }, nil } -func (p) Execute(cmd plugin.ExecutedCommand) error { +func (app) Execute(cmd plugin.ExecutedCommand) error { // TODO: write command execution here fmt.Printf("Hello I'm the <%= Name %> plugin\n") fmt.Printf("My executed command: %q\n", cmd.Path) @@ -75,17 +75,17 @@ func (p) Execute(cmd plugin.ExecutedCommand) error { return nil } -func (p) ExecuteHookPre(hook plugin.ExecutedHook) error { +func (app) ExecuteHookPre(hook plugin.ExecutedHook) error { fmt.Printf("Executing hook pre %q\n", hook.Name) return nil } -func (p) ExecuteHookPost(hook plugin.ExecutedHook) error { +func (app) ExecuteHookPost(hook plugin.ExecutedHook) error { fmt.Printf("Executing hook post %q\n", hook.Name) return nil } -func (p) ExecuteHookCleanUp(hook plugin.ExecutedHook) error { +func (app) ExecuteHookCleanUp(hook plugin.ExecutedHook) error { fmt.Printf("Executing hook cleanup %q\n", hook.Name) return nil } @@ -107,7 +107,7 @@ func getChain(cmd plugin.ExecutedCommand, chainOption ...chain.Option) (*chain.C func main() { pluginMap := map[string]hplugin.Plugin{ - "<%= Name %>": &plugin.InterfacePlugin{Impl: &p{}}, + "<%= Name %>": &plugin.InterfacePlugin{Impl: &app{}}, } hplugin.Serve(&hplugin.ServeConfig{ diff --git a/integration/plugin/plugin_test.go b/integration/plugin/plugin_test.go index 551ce600ee..813af11180 100644 --- a/integration/plugin/plugin_test.go +++ b/integration/plugin/plugin_test.go @@ -36,9 +36,9 @@ func TestAddRemovePlugin(t *testing.T) { // no plugins expected assertPlugins(nil, nil) - env.Must(env.Exec("add plugin locally", + env.Must(env.Exec("install plugin locally", step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "plugin", "add", pluginRepo, "k1=v1", "k2=v2"), + step.Exec(envtest.IgniteApp, "app", "install", pluginRepo, "k1=v1", "k2=v2"), step.Workdir(app.SourcePath()), )), )) @@ -57,9 +57,9 @@ func TestAddRemovePlugin(t *testing.T) { nil, ) - env.Must(env.Exec("remove plugin locally", + env.Must(env.Exec("uninstall plugin locally", step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "plugin", "remove", pluginRepo), + step.Exec(envtest.IgniteApp, "app", "uninstall", pluginRepo), step.Workdir(app.SourcePath()), )), )) @@ -67,9 +67,9 @@ func TestAddRemovePlugin(t *testing.T) { // no plugins expected assertPlugins(nil, nil) - env.Must(env.Exec("add plugin globally", + env.Must(env.Exec("install plugin globally", step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "plugin", "add", pluginRepo, "-g"), + step.Exec(envtest.IgniteApp, "app", "install", pluginRepo, "-g"), step.Workdir(app.SourcePath()), )), )) @@ -84,9 +84,9 @@ func TestAddRemovePlugin(t *testing.T) { }, ) - env.Must(env.Exec("remove plugin globally", + env.Must(env.Exec("uninstall plugin globally", step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "plugin", "remove", pluginRepo, "-g"), + step.Exec(envtest.IgniteApp, "app", "uninstall", pluginRepo, "-g"), step.Workdir(app.SourcePath()), )), )) @@ -100,9 +100,9 @@ func TestAddRemovePlugin(t *testing.T) { func TestPluginScaffold(t *testing.T) { env := envtest.New(t) - env.Must(env.Exec("add a plugin", + env.Must(env.Exec("install a plugin", step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "plugin", "scaffold", "test"), + step.Exec(envtest.IgniteApp, "app", "scaffold", "test"), step.Workdir(env.TmpDir()), )), ))