class Crowbar::Client::Command::Backup::List

Implementation for the backup list command

Public Instance Methods

execute() click to toggle source
# File lib/crowbar/client/command/backup/list.rb, line 34
def execute
  request.process do |request|
    case request.code
    when 200
      formatter = Formatter::Hash.new(
        format: provide_format,
        headings: headings,
        values: Filter::Hash.new(
          filter: provide_filter,
          values: content_from(request)
        ).result
      )

      if formatter.empty?
        err "No backups"
      else
        say formatter.result
      end
    else
      err request.parsed_response["error"]
    end
  end
end
request() click to toggle source
# File lib/crowbar/client/command/backup/list.rb, line 28
def request
  @request ||= Request::Backup::List.new(
    args
  )
end

Protected Instance Methods

content_from(request) click to toggle source
# File lib/crowbar/client/command/backup/list.rb, line 64
def content_from(request)
  request.parsed_response.map do |row|
    row.slice(
      "name",
      "created_at",
      "size",
      "version"
    ).tap do |values|
      values["size"] = number_to_human_size(
        values["size"]
      )
    end
  end
end
headings() click to toggle source
# File lib/crowbar/client/command/backup/list.rb, line 60
def headings
  ["Name", "Created", "Size", "Version"]
end