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

Add a --list-plugins hook #610

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hooks/boot/05-plugins.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
app_option('--list-plugins', :flag, "List all available plugins")
87 changes: 87 additions & 0 deletions hooks/pre_validations/05-plugins.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
if app_value(:list_plugins)

class Plugin
include Comparable

attr_reader :group, :plugin, :provider, :module

# We expect a mymod::plugin::myplugin structure but also allow
# mymod::plugin::myplugin::provider
def initialize(mod)
parts = mod.identifier.split('::')

raise ArgumentError, "#{mod.identifier} is not a plugin" unless parts.length >= 3

type = ['plugin', 'cli', 'compute'].detect { |type| parts.include?(type) }
raise ArgumentError, "#{mod.identifier} is not a plugin" unless type

index = parts.index(type)
if type == 'plugin'
@group = parts.slice(0, index).join(' ')
else
@group = parts.slice(0, index + 1).join(' ')
end
@plugin, @provider = parts.slice(index + 1, parts.length)

@module = mod
end

def name
provider || plugin
end

def to_s
mod.identifier
end

def inspect
"<Plugin:#{mod.identifier}>"
end
Comment on lines +33 to +39
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There aren't actually used and I couldn't quite get them to work in debugging. Perhaps they should be removed.


def <=>(other)
if group != other.group
group <=> other.group
elsif plugin != other.plugin
plugin <=> other.plugin
elsif provider
if other.provider
provider <=> other.provider
else
1
end
elsif other.provider
-1
else
0
end
end
end

groups = Hash.new { |h, k| h[k] = [] }

kafo.modules.each do |mod|
begin
plugin = Plugin.new(mod)
groups[plugin.group] << plugin
rescue ArgumentError
end
end

if groups.any?
groups.each do |group, plugins|
say "* #{group.tr('_', ' ').capitalize}"
plugins.sort.each do |plugin|
enabled = plugin.module.enabled? ? 'enabled' : 'disabled'
indenting = plugin.provider ? ' ' : ' '

# TODO: assumes there is a plugin but breaks with
# foreman_proxy::plugin::dns::powerdns because dns is built in
say "#{indenting}* #{plugin.name} (#{enabled})"
end
end
else
say "No plugins available in #{scenario_data.name}"
end

exit(0)
end