class S3Ranger::CLI::List

Attributes

max_entries[RW]

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/s3ranger/cli.rb, line 155
def initialize
  super 'list', false, false

  @short_desc = "List items filed under a given bucket"

  @max_entries = 0

  @delimiter = "\t"

  @has_prefix = true

  self.options = CmdParse::OptionParserWrapper.new do |opt|
    opt.on("-m", "--max-entries=NUM", "Limit the number of entries to output") {|m|
      @max_entries = m
    }

    opt.on("-d", "--delimiter=D", "Charactere used to separate columns") {|d|
      @delimiter = d
    }
  end
end

Public Instance Methods

run(s3, bucket, key, file, args) click to toggle source
# File lib/s3ranger/cli.rb, line 177
def run s3, bucket, key, file, args
  raise WrongUsage.new(nil, "You need to inform a bucket") if not bucket

  collection = s3.buckets[bucket].objects.with_prefix(key || "")

  if @max_entries > 0
    collection = collection.page(:per_page => @max_entries)
  end

  collection.each {|object|
    o = []
    o << object.key
    o << @delimiter
    o << object.content_length
    o << @delimiter
    o << object.last_modified
    puts o.join
  }
end