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
52
53
54
55
56
|
# File 'lib/cloudstack-cli/cli.rb', line 26
def setup(file = options[:config])
config = {}
unless options[:url]
say "Configuring #{options[:environment] || 'default'} environment."
say "What's the URL of your Cloudstack API?", :yellow
say "Example: https://my-cloudstack-service/client/api/"
config[:url] = ask("URL:", :magenta)
end
unless options[:api_key]
config[:api_key] = ask("API Key:", :magenta)
end
unless options[:secret_key]
config[:secret_key] = ask("Secret Key:", :magenta)
end
if options[:environment]
config = {options[:environment] => config}
end
if File.exists? file
begin
old_config = YAML::load(IO.read(file))
rescue
error "Can't load configuration from file #{config_file}."
error "To create a new configuration file run \"cs setup\"."
exit 1
end
say "Warning: #{file} already exists.", :red
exit unless yes?("Do you want to merge your settings? [y/N]", :red)
config = old_config.merge(config)
end
File.open(file, 'w+') {|f| f.write(config.to_yaml) }
end
|