lib/hackpad/config.rb in hackpad-cli-0.0.2 vs lib/hackpad/config.rb in hackpad-cli-0.0.3
- old
+ new
@@ -1,21 +1,27 @@
module Hackpad
module Config
extend self
- def load(dir = nil)
- if !Dir.exists?(conf_dir dir) || !File.exists?(conf_file)
- setup conf_dir dir
+ def load(options)
+ configdir = options[:configdir]
+ configfile = File.join(configdir, "#{options[:workspace]}.yml")
+ # temporary migration path
+ if !File.exists?(configfile) && File.exists?(File.join(configdir, "config.yml"))
+ FileUtils.mv File.join(configdir, "config.yml"), configfile
end
- YAML::load_file conf_file
+ if !Dir.exists?(configdir) || !File.exists?(configfile)
+ setup configfile
+ end
+ YAML::load_file configfile
end
private
- def setup(dir)
+ def setup(configfile)
config = {}
- FileUtils.mkdir_p dir
+ FileUtils.mkdir_p File.dirname(configfile)
puts "We need first to initialize your hackpad-cli configuration.".colorize(:blue)
puts "Please gather your information from https://<subdomain>.hackpad.com/ep/account/settings/"
print "What is your Client ID? "
STDOUT.flush
config['client_id'] = STDIN.gets.chomp
@@ -23,20 +29,12 @@
STDOUT.flush
config['secret'] = STDIN.gets.chomp
print "What is the URI of your pad? "
STDOUT.flush
config['site'] = STDIN.gets.chomp
- File.open(conf_file, "w") do |f|
+ File.open(configfile, "w") do |f|
f.write YAML::dump(config)
end
- end
-
- def conf_file
- File.join(conf_dir, 'config.yml')
- end
-
- def conf_dir(dir = "#{ENV["HOME"]}/.hackpad-cli/")
- dir
end
end
end