Class: BunBun::CLI::StorageEdit

Inherits:
StorageCommand show all
Defined in:
lib/bunbun/cli/storage_edit.rb

Instance Attribute Summary

Attributes inherited from StorageCommand

#storage_access_key, #storage_host, #storage_zone

Attributes inherited from Command

#options

Instance Method Summary collapse

Methods inherited from Command

argument_count, argument_names, option, #option_parser, options

Instance Method Details

#call(path) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/bunbun/cli/storage_edit.rb', line 6

def call(path)
  super

  response = client.download(path)

  unless response.content_type.start_with?('text/') || response.content_type == 'application/json'
    raise BunBun::CLI::Error, "cannot edit #{response.content_type} files"
  end

  text = response.body

  pipe = IO.popen(ENV.fetch('EDITOR'), 'w+')
  pipe.puts(text)
  pipe.close_write

  edited_text = pipe.read

  pipe.close

  unless edited_text.empty? || edited_text == text
    client.upload(path, edited_text, content_type: response.content_type)
  end
end