7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/slicehost-tools/tools.rb', line 7
def apikey(apikey = nil)
@write_file = false
unless File.exists? File.join(ENV['HOME'], '.slicehost-tools')
@write_file = true
else
print "This will replace the stored key, are you sure? [y/N] "
case STDIN.gets.chomp
when /y/i
@write_file = true
end
end
if apikey.nil? && @write_file
puts "Please enter your API key since you did not provide one: "
apikey = STDIN.gets.chomp
end
if @write_file
File.open( File.join(ENV['HOME'], '.slicehost-tools'), File::RDWR|File::TRUNC|File::CREAT, 0664 ) do |f|
f.puts "SlicehostSecretKey = '#{apikey}'"
f.close
end
end
end
|