lib/gitlab/cli_helpers.rb in gitlab-3.6.1 vs lib/gitlab/cli_helpers.rb in gitlab-3.7.0
- old
+ new
@@ -1,7 +1,8 @@
require 'yaml'
require 'json'
+require 'base64'
class Gitlab::CLI
# Defines methods related to CLI output and formatting.
module Helpers
extend self
@@ -89,11 +90,11 @@
end
# Outputs a nicely formatted table or error msg.
def output_table(cmd, args, data)
case data
- when Gitlab::ObjectifiedHash
+ when Gitlab::ObjectifiedHash, Gitlab::FileResponse
puts record_table([data], cmd, args)
when Gitlab::PaginatedResponse
puts record_table(data, cmd, args)
else # probably just an error msg
puts data
@@ -103,11 +104,11 @@
def output_json(cmd, args, data)
if data.empty?
puts '{}'
else
hash_result = case data
- when Gitlab::ObjectifiedHash
+ when Gitlab::ObjectifiedHash,Gitlab::FileResponse
record_hash([data], cmd, args, true)
when Gitlab::PaginatedResponse
record_hash(data, cmd, args)
else
{ cmd: cmd, data: data, args: args }
@@ -132,11 +133,13 @@
values = []
keys.each do |key|
case value = hash[key]
when Hash
- value = 'Hash'
+ value = value.has_key?('id') ? value['id'] : 'Hash'
+ when StringIO
+ value = 'File'
when nil
value = 'null'
end
values << value
@@ -166,9 +169,11 @@
keys.each do |key|
case hash[key]
when Hash
row[key] = 'Hash'
+ when StringIO
+ row[key] = Base64.encode64(hash[key].read)
when nil
row[key] = nil
else
row[key] = hash[key]
end