summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.markdown1
-rwxr-xr-xbin/hcl1
-rw-r--r--lib/hcl.rb44
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
diff --git a/bin/hcl b/bin/hcl
index 0e9346a..a968c5f 100755
--- a/bin/hcl
+++ b/bin/hcl
@@ -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
diff --git a/lib/hcl.rb b/lib/hcl.rb
index 3011413..d14fa8e 100644
--- a/lib/hcl.rb
+++ b/lib/hcl.rb
@@ -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