-
Notifications
You must be signed in to change notification settings - Fork 551
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
feat(plugin): execute from function #3899
Conversation
This change introduces a `plugin.Execute()` function that can be used to run arbitrary code without affecting the Ignite CLI dependencies. The code lives in its own repo, like any other plugins. Arguments can be passed to update the behavior. Once merged, this will be used to remove the interchain-security dependency from Ignite CLI which we currently have in #3660 (see discussions [0]) Because this will be used internally in Ignite CLI for specific cases, I don't feel that we need to document this feature in the official documentation. [0]: #3660 (comment)
@tbruyelle I left a comment in the original discussion that could eventually solve the original issue. The |
@jeronimoalbi There's currently two specific locations where the interchain-security package is imported:
To remove the interchain-security import, the idea is to move that code into a plugin repo, like https://github.com/tbruyelle/cli-plugin-consumer, and then replace the moved code by if cfg.IsConsumerChain() {
// Consumer chain writes validators in the consumer module genesis
err := plugin.Execute(ctx, "github.com/tbruyelle/cli-plugin-consumer", "writeGenesis")
if err != nil {
return fmt.Errorf("execute consumer plugin: %w", err)
}
} For the if cfg.IsConsumerChain() {
// Consumer chain writes validators in the consumer module genesis
// FIXME use constant for plugin path and args (or introduce new method in plugin/consumer.go)
err := plugin.Execute(context.Background(), "/home/tom/src/ignite/cli-plugin-consumer", "isInitialized")
if err != nil {
// FIXME convert to rpc status.Error to get access to desc
if errors.Cause(err).Error() == "not initialized" {
return false, nil
}
return false, fmt.Errorf("execute consumer plugin %q %T: %w", err.Error(), err, err)
}
} With these changes, the interchain-security is no longer present in the Ignite CLI go.mod. |
I wonder if adding |
That would be better yes, but I didn't want to change the plugin interface and break existing plugins. But maybe that doesn't really matter. The other point is there's already too many methods in the plugin interface, and adding a new one will increase again its complexity. Finally, since it's internal and not exposed to Ignite users, I think it's acceptable to use the |
Sorry this is wrong, |
Also: - redirect stdout/stderr to buffer, so Execute's client can read the plugin output - unwrap rpc status error - add more tests - add ChainInfo.Home (will be used for consumer plugin) - update .gitignore in plugin template to ignore also *.ign files
4dd4e3b
to
8e8cddc
Compare
This change introduces a
plugin.Execute()
function that can be used to run arbitrary code without affecting the Ignite CLI dependencies. The code lives in its own repo, like any other plugins. Arguments can be passed to update the behavior.Originally, plugins were designed to add new commands to the CLI, but it seems that, with minimal changes, it can be used for other purposes, such as the one described above.
Once merged, this will be used to remove the interchain-security dependency from Ignite CLI which we currently have in #3660 (see discussions 0)
Because this will be used internally in Ignite CLI for specific cases, I don't feel that we need to document this feature in the official documentation.