diff options
| author | Zack Hobson | 2009-07-24 18:52:27 -0700 |
|---|---|---|
| committer | Zack Hobson | 2009-07-24 18:52:36 -0700 |
| commit | b4b278997027d18f40cff419c987be58c4274fcf (patch) | |
| tree | d8a63bbdf20357133f9fda61a00f776a6b1b7bee /lib | |
| parent | 88e6dd743793715ab92008611a5e5e9a89e88147 (diff) | |
| download | hcl-b4b278997027d18f40cff419c987be58c4274fcf.tar.bz2 | |
Use ~/.hcl_config instead of ./hcl_conf.yml for credentials.
If no configuration is present the user will be prompted.
This closes #17.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/hcl.rb | 44 |
1 files changed, 33 insertions, 11 deletions
@@ -6,6 +6,7 @@ require 'net/https' require 'rubygems' require 'chronic' require 'trollop' +require 'highline/import' require 'hcl/timesheet_resource' require 'hcl/project' @@ -27,15 +28,12 @@ end class HCl VERSION = "0.1.0" SETTINGS_FILE = "#{ENV['HOME']}/.hcl_settings" + CONFIG_FILE = "#{ENV['HOME']}/.hcl_config" class UnknownCommand < StandardError; end - def self.conf_file= filename - @@conf_file = filename - end - def self.command *args - hcl = new(@@conf_file).process_args(*args).run + hcl = new.process_args(*args).run end def run @@ -50,9 +48,8 @@ class HCl end end - def initialize conf_file - config = YAML::load File.read(conf_file) - TimesheetResource.configure config + def initialize + read_config read_settings end @@ -96,10 +93,35 @@ EOM end end + def read_config + if File.exists? CONFIG_FILE + config = YAML::load File.read(CONFIG_FILE) + TimesheetResource.configure config + elsif File.exists? old_conf = File.dirname(__FILE__) + "/../hcl_conf.yml" + config = YAML::load File.read(old_conf) + TimesheetResource.configure config + write_config config + else + config = {} + puts "Please specify your Harvest credentials.\n" + config['login'] = ask("Email Address: ") + config['password'] = ask("Password: ") { |q| q.echo = false } + config['subdomain'] = ask("Subdomain: ") + TimesheetResource.configure config + write_config config + end + end + + def write_config config + puts "Writing configuration to #{CONFIG_FILE}." + File.open(CONFIG_FILE, 'w') do |f| + f.write config.to_yaml + end + end + def read_settings - settings_file = "#{ENV['HOME']}/.hcl_settings" - if File.exists? settings_file - @settings = YAML.load(File.read(settings_file)) + if File.exists? SETTINGS_FILE + @settings = YAML.load(File.read(SETTINGS_FILE)) else @settings = {} end |
