Sha256: 3fa12ddce4766855a0512285ad91044033c07a381fb5c4a59d68bd058a02ec42

Contents?: true

Size: 1.98 KB

Versions: 2

Compression:

Stored size: 1.98 KB

Contents

require 'hammer_cli_foreman/filter'

module HammerCLIForeman

  class Role < HammerCLIForeman::Command

    resource :roles

    class ListCommand < HammerCLIForeman::ListCommand
      output do
        field :id, _("Id")
        field :name, _("Name")
      end

      build_options
    end

    class InfoCommand < HammerCLIForeman::InfoCommand
      output ListCommand.output_definition do
        field :builtin_text, _("Builtin")
      end

      def extend_data(data)
        data['builtin_text'] = (data['builtin'].to_i > 0) ? _('Yes') : _('No')
        data
      end

      build_options
    end


    class FiltersCommand < HammerCLIForeman::ListCommand
      command_name "filters"
      resource :filters, :index

      option "--id", "ID", _("User role id"), :referenced_resource => 'role'

      output HammerCLIForeman::Filter::ListCommand.output_definition

      def request_params
        role_id = get_resource_id(HammerCLIForeman.foreman_resource(:roles))
        { :search => "role_id = \"#{role_id}\"" }
      end

      def extend_data(filter)
        filter['resource_type'] ||= _("(Miscellaneous)")
        filter['search'] ||= _("none")
        filter['permissions'] = filter.fetch('permissions', []).collect{|p| p["name"]}
        filter
      end

      build_options do |o|
        o.expand.primary(:roles)
        o.without(:search)
      end
    end


    class CreateCommand < HammerCLIForeman::CreateCommand
      success_message _("User role [%<name>s] created")
      failure_message _("Could not create the user role")

      build_options
    end


    class UpdateCommand < HammerCLIForeman::UpdateCommand
      success_message _("User role [%<name>s] updated")
      failure_message _("Could not update the user role")

      build_options
    end


    class DeleteCommand < HammerCLIForeman::DeleteCommand
      success_message _("User role [%<name>s] deleted")
      failure_message _("Could not delete the user roles")

      build_options
    end

    autoload_subcommands
  end

end



Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hammer_cli_foreman-0.5.1 lib/hammer_cli_foreman/role.rb
hammer_cli_foreman-0.5.0 lib/hammer_cli_foreman/role.rb