Skip to content
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

Plugin CLI options not bound until after register is called #2703

Open
antonydenyer opened this issue Aug 31, 2021 · 2 comments
Open

Plugin CLI options not bound until after register is called #2703

antonydenyer opened this issue Aug 31, 2021 · 2 comments
Labels
enhancement New feature or request plugins

Comments

@antonydenyer
Copy link
Member

Description

As a plugin developer, I want access to the cli options that are pertinent to my plugin during the registration phase. The reason for this is that I may not wish to register my plugin if it's not enabled/configured correctly. The problem is that we have a catch 22 with regards to registering PicoCLIOptions. The only place you can register PicoCLIOptions is in the register method, this is, obviously, too late if you are expecting those parameters to be bound at that point in time.

@AutoService(BesuPlugin.class)
public class MyMetricsPlugin implements BesuPlugin {

  @Option(
      names = {"--plugin-metrics-enabled"},
      description = "Enable Metrics plugin")
  private boolean enabled;

  @Override
  public void register(final BesuContext context) {
    final PicoCLIOptions cmdlineOptions = context.getService(PicoCLIOptions.class).get();
    cmdlineOptions.addPicoCLIOptions("metrics", this);
   
    if (enabled) {
      // register metrics category
      ...
    }

  }
  ... 
}

Obviously, this will not work because enabled will always equal false.

We need a better way of allowing plugin developers to configure command-line arguments.

Options

Add an optional method to the BesuPlugin interface

Something like

  void initialize(PicoCLIOptions options);

would allow a plugin developer to call addPicoCLIOptions before register is called.

Always mixin BesuPlugin classes

Another option is to always 'mixin' the plugin class. This would mean that a plugin implementor would only be able to register options in a class that implements BesuPlugin. But would not need to explicitly call addPicoCLIOptions anywhere.

Backwards compatibility

Either option, or both, could be added whilst maintaining the current behaviour.

@macfarla
Copy link
Contributor

macfarla commented Dec 6, 2024

@jflo @Gabriel-Trintinalia is this issue still relevant?

@jflo
Copy link
Contributor

jflo commented Dec 6, 2024

Yes, this is an important plugin lifecycle adjustment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request plugins
Projects
None yet
Development

No branches or pull requests

3 participants