250: def initialize( cmdparser )
251: super( 'show', true )
252: self.short_desc = "Shows various information"
253:
254:
255: showPlugins = CmdParse::Command.new( 'plugins', false )
256: showPlugins.short_desc = "Shows the available plugins"
257: showPlugins.set_execution_block do |args|
258: puts "List of loaded plugins:"
259: headers = Hash.new {|h,k| h[k] = (k.nil? ? "Other Plugins" : k.gsub(/([A-Z][a-z])/, ' \1').strip) }
260:
261: header = ''
262: cmdparser.website.manager.plugin_classes.sort {|a, b| a.plugin_name <=> b.plugin_name }.each do |plugin|
263: newHeader = headers[plugin.plugin_name[/^.*?(?=\/)/]]
264: unless newHeader == header
265: puts "\n" + CliUtils.headline( newHeader )
266: header = newHeader
267: end
268: puts CliUtils.section( plugin.plugin_name[/\w+$/], 33 ) + CliUtils.format( plugin.config.infos[:summary], 33 ).join("\n")
269: end
270: end
271: self.add_command( showPlugins )
272:
273:
274: showConfig = CmdParse::Command.new( 'config', false )
275: showConfig.short_desc = "Shows information like the parameters for all or the matched plugins"
276: showConfig.description =
277: CliUtils.format( "\nIf no argument is provided, all plugins and their information are listed. If " +
278: "an argument is specified, all plugin names that match the argument are listed." ).join("\n")
279: showConfig.set_execution_block do |args|
280: puts "List of plugin informations:"
281: puts
282:
283: cmdparser.website.manager.plugins.sort {|a, b| a[0] <=> b[0] }.each do |name, plugin|
284: next if args.length > 0 && /#{args[0]}/i !~ name
285:
286: config = plugin.class.config
287: puts CliUtils.headline( name )
288: ljust = 25
289:
290: puts CliUtils.section( 'Summary', ljust ) + CliUtils.format( config.infos[:summary], ljust ).join("\n") if config.infos[:summary]
291: puts CliUtils.section( 'Author', ljust ) + CliUtils.format( config.infos[:author], ljust ).join("\n") if config.infos[:author]
292: puts CliUtils.section( 'Description', ljust ) + CliUtils.format( config.infos[:description], ljust ).join("\n") if config.infos[:description]
293: puts CliUtils.section( 'Tag names', ljust ) + plugin.tags.join(", ") if plugin.respond_to?( :tags )
294: puts CliUtils.section( 'Handles paths', ljust ) + plugin.path_patterns.collect {|r,f| f}.inspect if plugin.respond_to?( :path_patterns )
295: puts CliUtils.section( 'Dependencies', ljust ) + config.dependencies.join(', ') if !config.dependencies.empty?
296:
297: if !config.params.empty?
298: puts "\n" + CliUtils.section( 'Parameters' )
299: config.params.sort.each do |name, item|
300: print "\n" + CliUtils.section( 'Parameter', ljust, 6 )
301: puts Color.lred( item.name ) + ": " + Color.lblue( plugin.instance_eval {param( name )}.inspect ) +
302: " (" + item.default.inspect + ")"
303: puts CliUtils.section( 'Description', ljust, 6 ) + CliUtils.format( item.description, ljust ).join("\n")
304: end
305: end
306:
307: otherinfos = config.infos.select {|k,v| ![:name, :author, :summary, :description, :tags, :path_patterns].include?( k ) }
308: puts "\n" +CliUtils.section( 'Other Information' ) unless otherinfos.empty?
309: otherinfos.each {|name, value| puts CliUtils.section( name.to_s.tr('_', ' '), ljust, 6 ) + value.inspect }
310:
311: puts
312: end
313: end
314: self.add_command( showConfig )
315: end