Im creating a pluggable CLI tool that allows users to add plugins in the form of picocli subcommands to a host picocli app.
I want to be able to supply the plugins with shared functionality such as http communication with a server defined in a user profile on the main app. As I have it now I just have an api for the extension point that contains the service, which is the initialised on plugin load, but this only works for a single service, and requires all plugins to have the service.
interface CliPlugin : ExtensionPoint {
val version: String
var httpService: HttpService
fun setHttpService(httpService: HttpService)
}
The plugins look like this:
@Extension
@CommandLine.Command(name = "example", subcommands = [SubCommandOne::class])
class WelcomeCliPlugin : CliPlugin {
override lateinit var service: HttpService
override val pluginId: String
get() = "WelcomePlugin"
override fun setHttpService(httpService: HttpService){
this.service = httpService
}
}
then in the root app I can set it by simply calling setHttpService on all plugins. This is a bad pattern, I know it is, what is a better way of achieving this for several services?