Class: S3Ranger::CLI::List

Inherits:
BaseCmd
  • Object
show all
Defined in:
lib/s3ranger/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseCmd

#has_options?, #has_prefix?, #usage

Constructor Details

#initializeList

Returns a new instance of List.



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# 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

Instance Attribute Details

#max_entriesObject

Returns the value of attribute max_entries.



153
154
155
# File 'lib/s3ranger/cli.rb', line 153

def max_entries
  @max_entries
end

Instance Method Details

#run(s3, bucket, key, file, args) ⇒ Object

Raises:



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# 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