Method: HP::Cloud::CLI#list

Defined in:
lib/hpcloud/commands/list.rb

#list(*sources) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/hpcloud/commands/list.rb', line 50

def list(*sources)
  cli_command(options) {
    sources = [""] if sources.empty?
    multi = sources.length > 1
    opt = {}
    opt[Columns.option_name] = options[Columns.option_name]
    opt[Tableizer.option_name] = options[Tableizer.option_name]
    if options[:long]
      longlist = true
    else
      if options[:sync]
        longlist = true
      else
        longlist = false
        opt[Tableizer.option_name] = ' ' if opt[Tableizer.option_name].nil?
      end
    end
    sources.each { |name|
      sub_command {
        from = ResourceFactory.create(Connection.instance.storage, name)
        if from.valid_source()
          multi = true unless from.is_container?
          if multi
            keys = [ "lname" ]
          else
            keys = [ "sname" ]
          end
          if longlist == true
            if from.is_object_store?
              if options[:sync]
                keys += [ "count", "size", "synckey", "syncto" ]
              else
                keys += [ "count", "size" ]
              end
            else
              keys += [ "size", "type", "etag", "modified" ]
            end
          end
          tableizer = Tableizer.new(opt, keys)
          from.foreach { |file|
            if options[:sync]
              file.container_head(true)
            end
            tableizer.add(file.to_hash)
          }
          tableizer.print


          if tableizer.found == false
            if from.is_object_store?
              @log.error "Cannot find any containers, use `#{selfname} containers:add <name>` to create one.", :not_found
            elsif from.isDirectory() == false
              @log.error "Cannot find resource named '#{name}'.", :not_found
            end
          end
        else
          @log.error from.cstatus
        end
      }
    }
  }
end