Class: Awshark::S3::Subcommand

Inherits:
Thor
  • Object
show all
Includes:
ActiveSupport::NumberHelper, ClassOptions
Defined in:
lib/awshark/s3/subcommand.rb

Instance Method Summary collapse

Methods included from ClassOptions

#process_class_options

Instance Method Details

#listObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/awshark/s3/subcommand.rb', line 23

def list
  process_class_options

  buckets = manager.list_buckets
  args = {
    name: 'Bucket',
    region: 'Region',
    size: 'Size',
    number_of_objects: 'Number of Objects'
  }
  printf "  %-40<name>s %-13<region>s %-10<size>s %<number_of_objects>s\n", args
  buckets.each do |bucket|
    args = {
      name: bucket.name,
      region: bucket.region,
      size: number_to_human_size(bucket.byte_size),
      number_of_objects: bucket.number_of_objects
    }
    printf "  %-40<name>s %-13<region>s %-10<size>s %<number_of_objects>i\n", args
  end
end

#objects(bucket, prefix = '') ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/awshark/s3/subcommand.rb', line 51

def objects(bucket, prefix = '')
  process_class_options

  objects = manager.list_objects(bucket: bucket, prefix: prefix)

  objects.each do |o|
    filesize = number_to_human_size(o.size)
    printf "  %-10<size>s %<key>s\n", key: o.key, size: filesize
  end
  printf "\n\n  Total:\n"
  printf "  %<size>s objects\n", size: objects.size
  printf "  %<size>s\n", size: number_to_human_size(objects.map(&:size).sum)
end

#update_metadata(bucket, prefix) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/awshark/s3/subcommand.rb', line 72

def (bucket, prefix)
  process_class_options

  objects = manager.list_objects(bucket: bucket, prefix: prefix)
  meta = (options[:meta] || {}).symbolize_keys

  puts "Metadata: #{JSON.pretty_generate(meta)}"
  puts 'Updating ...'
  objects.each do |o|
    manager.(bucket, o.key, meta)
    printf " %<key>s \n", key: o.key
  end
end