Class: Superbot::Cloud::CLI::Test::DownloadCommand

Inherits:
BaseCommand show all
Defined in:
lib/superbot/cloud/cli/test/download_command.rb

Instance Method Summary collapse

Methods inherited from LoginRequiredCommand

#run, run

Methods included from Validations

#require_login

Instance Method Details

#download_testObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/superbot/cloud/cli/test/download_command.rb', line 17

def download_test
  puts "Downloading #{name}..."
  test = Superbot::Cloud::Api.request(
    :test_download,
    params: {
      name: name,
      organization_name: organization
    }
  )

  if Dir.exist?(test[:name])
    puts "Directory #{test[:name]} already exists"
    print "Override files? [Y/n] "
    answer = $stdin.gets.rstrip
    abort "Aborted." unless answer.downcase.start_with?('y') || answer.empty?
  end

  FileUtils.mkdir_p test[:name]
  test[:files].each do |file|
    File.write(File.join(test[:name], file[:filename]), file[:content])
    print file[:filename], ' - ', 'Success'
    puts
  end
  puts "Test files successfully downloaded to #{File.join(Dir.pwd, test[:name])}"
end

#executeObject



13
14
15
# File 'lib/superbot/cloud/cli/test/download_command.rb', line 13

def execute
  download_test
end