Class: HammerCLIForeman::ListCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/hammer_cli_foreman/commands.rb

Direct Known Subclasses

Architecture::ListCommand, AssociatedListSearchCommand, AssociatedResourceListCommand, Audit::ListCommand, AuthSource::ListCommand, AuthSourceExternal::ListCommand, AuthSourceLdap::ListCommand, Bookmark::ListCommand, Combination::ListCombination, CommonParameter::ListCommand, ComputeProfile::ListCommand, ComputeResource::AvailableClustersCommand, ComputeResource::AvailableFlavorsCommand, ComputeResource::AvailableFoldersCommand, ComputeResource::AvailableImagesCommand, ComputeResource::AvailableNetworksCommand, ComputeResource::AvailableResourcePoolsCommand, ComputeResource::AvailableSecurityGroupsCommand, ComputeResource::AvailableStorageDomainsCommand, ComputeResource::AvailableStoragePodsCommand, ComputeResource::AvailableVirtualMachinesCommand, ComputeResource::AvailableVnicProfilesCommand, ComputeResource::AvailableZonesCommand, ComputeResource::ListCommand, ConfigReport::ListCommand, Domain::ListCommand, ExternalUsergroup::ListCommand, ExternalUsergroup::RefreshExternalUsergroupsCommand, Fact::ListCommand, Filter::AvailablePermissionsCommand, Filter::AvailableResourcesCommand, Filter::ListCommand, Host::ConfigReportsCommand, Host::ListCommand, Host::ReportsCommand, Hostgroup::ListCommand, HttpProxy::ListCommand, Image::AvailableImagesCommand, Image::ListCommand, Interface::ListCommand, HammerCLIForeman::Location::ListCommand, MailNotification::ListCommand, Medium::ListCommand, Model::ListCommand, OperatingSystem::ListCommand, Organization::ListCommand, PartitionTable::ListCommand, PersonalAccessToken::ListCommand, Realm::ListCommand, ReportTemplate::ListCommand, Role::FiltersCommand, Role::ListCommand, SSHKeys::ListCommand, Settings::ListCommand, SmartProxy::ListCommand, Subnet::ListCommand, Template::ListCommand, Template::ListKindsCommand, User::ListCommand, UserMailNotification::ListCommand, Usergroup::ListCommand

Constant Summary collapse

RETRIEVE_ALL_PER_PAGE =
1000
DEFAULT_PER_PAGE =
20

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

alias_name_for_resource, build_options, connection_name, create_option_builder, #customized_options, #dependency_resolver, dependency_resolver, #exception_handler_class, #get_identifier, #get_resource_id, #get_resource_ids, #request_params, resolver, #resolver, resource_alias_name_mapping, resource_config, resource_name_mapping, #searchables, searchables

Class Method Details

.command_names(*names) ⇒ Object



270
271
272
# File 'lib/hammer_cli_foreman/commands.rb', line 270

def self.command_names(*names)
  super(*names) || %w(list index)
end

.output(definition = nil, &block) ⇒ Object



243
244
245
246
247
248
249
250
# File 'lib/hammer_cli_foreman/commands.rb', line 243

def self.output(definition = nil, &block)
  super
  begin
    output_definition.update_field_sets('THIN', (searchables.for(resource).map(&:name) + ['id']).map(&:to_sym))
  rescue StandardError => e
    # Some subcommands may not have such fields or defined resource
  end
end

Instance Method Details

#adapterObject



252
253
254
# File 'lib/hammer_cli_foreman/commands.rb', line 252

def adapter
  @context[:adapter] || :table
end

#executeObject



274
275
276
277
278
279
280
281
282
283
284
# File 'lib/hammer_cli_foreman/commands.rb', line 274

def execute
  if should_retrieve_all?
    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) ⇒ Object



266
267
268
# File 'lib/hammer_cli_foreman/commands.rb', line 266

def extend_data(record)
  record
end

#helpObject



286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/hammer_cli_foreman/commands.rb', line 286

def help
  return super unless resource

  meta = resource.action(action).apidoc&.dig(:metadata)
  if meta && meta[:search] && respond_to?(:option_search)
    self.class.extend_help do |h|
      h.section(_('Search / Order fields'), id: :search_fields_section) do |h|
        h.list(search_fields_help(meta[:search]))
      end
    end
  end
  super
end

#send_requestObject



256
257
258
259
260
# File 'lib/hammer_cli_foreman/commands.rb', line 256

def send_request
  set = super
  set.map! { |r| extend_data(r) }
  set
end

#transform_format(data) ⇒ Object



262
263
264
# File 'lib/hammer_cli_foreman/commands.rb', line 262

def transform_format(data)
  HammerCLIForeman.collection_to_common_format(data)
end