class HammerCLIForeman::ListCommand
Constants
- DEFAULT_PER_PAGE
- RETRIEVE_ALL_PER_PAGE
Public Class Methods
command_name(name=nil)
click to toggle source
Calls superclass method
# File lib/hammer_cli_foreman/commands.rb, line 240 def self.command_name(name=nil) super(name) || "list" end
Public Instance Methods
adapter()
click to toggle source
# File lib/hammer_cli_foreman/commands.rb, line 222 def adapter @context[:adapter] || :table end
execute()
click to toggle source
# File lib/hammer_cli_foreman/commands.rb, line 244 def execute if should_retrieve_all? print_data(retrieve_all) else self.option_page = (self.option_page || 1).to_i if respond_to?(:option_page) self.option_per_page = (self.option_per_page || HammerCLI::Settings.get(:ui, :per_page) || DEFAULT_PER_PAGE).to_i if respond_to?(:option_per_page) print_data(send_request) end return HammerCLI::EX_OK end
extend_data(record)
click to toggle source
# File lib/hammer_cli_foreman/commands.rb, line 236 def extend_data(record) record end
help()
click to toggle source
Calls superclass method
# File lib/hammer_cli_foreman/commands.rb, line 256 def help meta = resource.action(action).apidoc[:metadata] return super if meta.nil? if meta && meta[:search] && respond_to?(:option_search) self.class.extend_help do |h| h.section(_('Search fields'), id: :search_fields_section) do |h| h.list(search_fields_help(meta[:search])) end end end super end
send_request()
click to toggle source
Calls superclass method
HammerCLIForeman::Command#send_request
# File lib/hammer_cli_foreman/commands.rb, line 226 def send_request set = super set.map! { |r| extend_data(r) } set end
transform_format(data)
click to toggle source
# File lib/hammer_cli_foreman/commands.rb, line 232 def transform_format(data) HammerCLIForeman.collection_to_common_format(data) end
Protected Instance Methods
pagination_supported?()
click to toggle source
# File lib/hammer_cli_foreman/commands.rb, line 287 def pagination_supported? respond_to?(:option_page) && respond_to?(:option_per_page) end
retrieve_all()
click to toggle source
# File lib/hammer_cli_foreman/commands.rb, line 272 def retrieve_all self.option_per_page = RETRIEVE_ALL_PER_PAGE self.option_page = 1 d = send_request all = d while (d.size == RETRIEVE_ALL_PER_PAGE) do self.option_page += 1 d = send_request all += d end all end
search_field_help_value(field)
click to toggle source
# File lib/hammer_cli_foreman/commands.rb, line 307 def search_field_help_value(field) if field[:values] && field[:values].is_a?(Array) _('Values') + ': ' + field[:values].join(', ') else field[:type] || field[:values] end end
search_fields_help(search_fields)
click to toggle source
# File lib/hammer_cli_foreman/commands.rb, line 297 def search_fields_help(search_fields) return [] if search_fields.nil? search_fields.each_with_object([]) do |field, help_list| help_list << [ field[:name], search_field_help_value(field) ] end end
should_retrieve_all?()
click to toggle source
# File lib/hammer_cli_foreman/commands.rb, line 291 def should_retrieve_all? retrieve_all = pagination_supported? && option_per_page.nil? && option_page.nil? retrieve_all &&= HammerCLI::Settings.get(:ui, :per_page).nil? if output.adapter.paginate_by_default? retrieve_all end