lib/milc/gcloud/resource.rb in milc-0.1.3 vs lib/milc/gcloud/resource.rb in milc-0.1.4
- old
+ new
@@ -46,14 +46,14 @@
def initialize(project, service, resource, commands)
@project, @service, @resource = project, service, resource
@commands = commands || []
end
- def __gcloud(cmd, &block)
+ def __gcloud(cmd, options = {}, &block)
c = "gcloud #{cmd} --format json"
c << " --project #{project}" unless c =~ /\s\-\-project[\s\=]/
- res = Gcloud.backend.execute(c, &block)
+ res = Gcloud.backend.execute(c, options, &block)
res ? JSON.parse(res) : nil
end
def build_attr_arg(attr_name, value)
"--#{attr_name.to_s.gsub(/\_/, '-')} #{value}"
@@ -67,10 +67,14 @@
attrs.map{|k,v| "#{k.to_s.gsub(/\_/, '-')}=#{v}" }.join(" ")
end
def call_action(action, cmd_args, attrs = nil, &block)
attr_args = attrs.nil? ? '' : build_attr_args(attrs)
- __gcloud("#{service} #{resource} #{action} #{cmd_args} #{attr_args}", &block)
+ options =
+ action =~ /\Alist|\Adescribe|\Aget/ ?
+ {returns: :stdout, logging: :stderr} :
+ {returns: :none , logging: :both}
+ __gcloud("#{service} #{resource} #{action} #{cmd_args} #{attr_args}", options, &block)
end
def call_update(cmd_args, attrs, &block)
call_action(:update, cmd_args, attrs, &block)
end