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 | |
| 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.
| -rw-r--r-- | README.markdown | 1 | ||||
| -rwxr-xr-x | bin/hcl | 1 | ||||
| -rw-r--r-- | lib/hcl.rb | 44 | 
3 files changed, 34 insertions, 12 deletions
diff --git a/README.markdown b/README.markdown index 2127d45..cdd8749 100644 --- a/README.markdown +++ b/README.markdown @@ -20,6 +20,7 @@ NOTE This software is nowhere near complete. To try it out:   * RubyGems   * Trollop option-parsing library (gem install trollop)   * Chronic date-parsing library (gem install chronic) + * HighLine console input library (gem install highline)  ## Usage @@ -5,6 +5,5 @@ $:.unshift File.dirname(__FILE__) + '/../ext/harvest/lib'  require 'hcl' -HCl.conf_file = File.dirname(__FILE__) + '/../hcl_conf.yml'  HCl.command *ARGV @@ -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  | 
