Sha256: 87f6cbaefd7d118b99943f3d8fec715c1308f44fbfdb616083abba5225e2e305

Contents?: true

Size: 1.19 KB

Versions: 30

Compression:

Stored size: 1.19 KB

Contents

module HammerCLIForeman
  module OptionSources
    class IdsParams < HammerCLI::Options::Sources::Base
      def initialize(command)
        @command = command
      end

      def param_updatable?(param_resource)
        param_resource && @command.respond_to?(HammerCLI.option_accessor_name("#{param_resource.singular_name}_ids"))
      end

      def available_ids_params
        IdArrayParamsFilter.new(:only_required => false).for_action(@command.resource.action(@command.action))
      end

      def get_options(defined_options, result)
        return result if @command.action.nil?
        # resolve all '<resource_name>_ids' parameters if they are defined as options
        available_ids_params.each do |api_param|
          param_resource = HammerCLIForeman.param_to_resource(api_param.name)
          if result[HammerCLI.option_accessor_name(api_param.name)].nil? && param_updatable?(param_resource)
            resource_ids = @command.get_resource_ids(param_resource, :scoped => true, :required => api_param.required?, :all_options => result)
            result[HammerCLI.option_accessor_name(api_param.name)] = resource_ids if resource_ids
          end
        end
        result
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
hammer_cli_foreman-2.5.2 lib/hammer_cli_foreman/option_sources/ids_params.rb
hammer_cli_foreman-2.5.1 lib/hammer_cli_foreman/option_sources/ids_params.rb
hammer_cli_foreman-2.5.0 lib/hammer_cli_foreman/option_sources/ids_params.rb
hammer_cli_foreman-2.3.2 lib/hammer_cli_foreman/option_sources/ids_params.rb
hammer_cli_foreman-2.4.0 lib/hammer_cli_foreman/option_sources/ids_params.rb
hammer_cli_foreman-2.3.1 lib/hammer_cli_foreman/option_sources/ids_params.rb
hammer_cli_foreman-2.3.0 lib/hammer_cli_foreman/option_sources/ids_params.rb
hammer_cli_foreman-2.1.3 lib/hammer_cli_foreman/option_sources/ids_params.rb
hammer_cli_foreman-2.2.0 lib/hammer_cli_foreman/option_sources/ids_params.rb
hammer_cli_foreman-2.1.2 lib/hammer_cli_foreman/option_sources/ids_params.rb
hammer_cli_foreman-2.1.1 lib/hammer_cli_foreman/option_sources/ids_params.rb
hammer_cli_foreman-2.1.0 lib/hammer_cli_foreman/option_sources/ids_params.rb
hammer_cli_foreman-2.0.2 lib/hammer_cli_foreman/option_sources/ids_params.rb
hammer_cli_foreman-2.0.1 lib/hammer_cli_foreman/option_sources/ids_params.rb
hammer_cli_foreman-2.0.0 lib/hammer_cli_foreman/option_sources/ids_params.rb
hammer_cli_foreman-0.19.7 lib/hammer_cli_foreman/option_sources/ids_params.rb
hammer_cli_foreman-0.19.6 lib/hammer_cli_foreman/option_sources/ids_params.rb
hammer_cli_foreman-0.19.5 lib/hammer_cli_foreman/option_sources/ids_params.rb
hammer_cli_foreman-0.19.4 lib/hammer_cli_foreman/option_sources/ids_params.rb
hammer_cli_foreman-0.19.3 lib/hammer_cli_foreman/option_sources/ids_params.rb