Skip to content

Commit

Permalink
feat: add plugin-resolver flag
Browse files Browse the repository at this point in the history
  • Loading branch information
christophwitzko committed Jun 13, 2022
1 parent 1b57e43 commit a99c38e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pkg/config/config.go
Expand Up @@ -39,6 +39,7 @@ type Config struct {
DownloadPlugins bool
ShowProgress bool
AllowMaintainedVersionOnDefaultBranch bool
PluginResolver string
}

func mustGetString(cmd *cobra.Command, name string) string {
Expand Down Expand Up @@ -130,6 +131,7 @@ func NewConfig(cmd *cobra.Command) (*Config, error) {
DownloadPlugins: mustGetBool(cmd, "download-plugins"),
ShowProgress: mustGetBool(cmd, "show-progress"),
AllowMaintainedVersionOnDefaultBranch: mustGetBool(cmd, "allow-maintained-version-on-default-branch"),
PluginResolver: viper.GetString("pluginResolver"),
}
return conf, nil
}
Expand Down Expand Up @@ -187,6 +189,7 @@ func SetFlags(cmd *cobra.Command) {
cmd.Flags().Bool("show-progress", false, "shows the plugin download progress")
cmd.Flags().String("config", "", "config file (default is .semrelrc)")
cmd.Flags().Bool("allow-maintained-version-on-default-branch", false, "allow configuring the maintained version on the default branch")
cmd.Flags().String("plugin-resolver", "registry", "which resolver should be used to resolve plugins (registry or github)")
cmd.Flags().SortFlags = true

must(viper.BindPFlag("maintainedVersion", cmd.Flags().Lookup("maintained-version")))
Expand All @@ -198,6 +201,9 @@ func SetFlags(cmd *cobra.Command) {
must(viper.BindPFlag("plugins.changelog-generator.name", cmd.Flags().Lookup("changelog-generator")))
must(viper.BindPFlag("plugins.files-updater.names", cmd.Flags().Lookup("files-updater")))
must(viper.BindPFlag("plugins.hooks.names", cmd.Flags().Lookup("hooks")))

must(viper.BindPFlag("pluginResolver", cmd.Flags().Lookup("plugin-resolver")))
must(viper.BindEnv("pluginResolver", "SEMREL_PLUGIN_RESOLVER"))
}

func InitConfig(cmd *cobra.Command) error {
Expand Down
6 changes: 5 additions & 1 deletion pkg/plugin/discovery/discovery.go
Expand Up @@ -38,7 +38,11 @@ func New(config *config.Config) (*Discovery, error) {
return nil, err
}
// use the registry resolver as default
resolvers["default"] = resolvers["registry"]
resolvers["default"] = resolvers[config.PluginResolver]

if resolvers["default"] == nil {
return nil, fmt.Errorf("resolver %s does not exist", config.PluginResolver)
}

return &Discovery{
config: config,
Expand Down

0 comments on commit a99c38e

Please sign in to comment.