Class: C66Login::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/c66_login/cli.rb

Instance Method Summary collapse

Instance Method Details

#addObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/c66_login/cli.rb', line 8

def add
  puts "Warning: this process deletes your current cx.json file"
  #enter name for account
  puts "Enter this accounts email: "
  email = $stdin.gets.chomp

  File.delete("#{ENV['HOME']}/.cloud66/cx.json") if File.exists?("#{ENV['HOME']}/.cloud66/cx.json")

  system "cx stacks"

  FileUtils.cp("#{ENV['HOME']}/.cloud66/cx.json", "#{ENV['HOME']}/.cloud66/#{email}.json")

  puts "created #{email}.json and logged in"
end

#loginObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/c66_login/cli.rb', line 24

def 
  files = []
  i = 0
  indexes = []
  puts "Found auth tokens: "
  Dir.foreach("#{ENV['HOME']}/.cloud66") do |file|
    next if file == '.' or file == '..' or file == 'cx.json'
    puts "[#{i}] #{file}"
    files << file
    indexes << i
    i += 1
  end

  if i == 0
    puts "Couldn't find any auth files"
    return false
  end

  while true do
    puts "\nSelect index to auth login with: "
    file_index = Integer($stdin.gets.chomp)
    break if indexes.include?(file_index)
  end
  FileUtils.cp("#{ENV['HOME']}/.cloud66/#{files[file_index]}", "#{ENV['HOME']}/.cloud66/cx.json")
  puts "Logging in as: #{files[file_index]}"

  return true
end