Class: S3Ranger::CLI::List
- Defined in:
- lib/s3ranger/cli.rb
Instance Attribute Summary collapse
-
#max_entries ⇒ Object
Returns the value of attribute max_entries.
Instance Method Summary collapse
-
#initialize ⇒ List
constructor
A new instance of List.
- #run(s3, bucket, key, file, args) ⇒ Object
Methods inherited from BaseCmd
#has_options?, #has_prefix?, #usage
Constructor Details
#initialize ⇒ List
Returns a new instance of List.
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/s3ranger/cli.rb', line 150 def initialize super 'list', false, false @short_desc = "List items filed under a given bucket" @max_entries = 0 @delimiter = "\t" @has_prefix = true self. = 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_entries ⇒ Object
Returns the value of attribute max_entries.
148 149 150 |
# File 'lib/s3ranger/cli.rb', line 148 def max_entries @max_entries end |
Instance Method Details
#run(s3, bucket, key, file, args) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/s3ranger/cli.rb', line 172 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 = @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 |