diff options
| author | Zack Hobson | 2013-12-22 01:08:16 -0800 |
|---|---|---|
| committer | Zack Hobson | 2013-12-22 01:08:16 -0800 |
| commit | 971966cd2810c44244b63078122485456d92b27a (patch) | |
| tree | ecad11bb0383e058338f4f0722900f86ac2f981a /lib | |
| parent | 01d3ab8eb614186f083c9c9ced51ce697f751353 (diff) | |
| download | hcl-971966cd2810c44244b63078122485456d92b27a.tar.bz2 | |
add command `config` to display current configuration
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/hcl/app.rb | 2 | ||||
| -rw-r--r-- | lib/hcl/commands.rb | 6 | ||||
| -rw-r--r-- | lib/hcl/timesheet_resource.rb | 8 |
3 files changed, 14 insertions, 2 deletions
diff --git a/lib/hcl/app.rb b/lib/hcl/app.rb index e58921f..18d293c 100644 --- a/lib/hcl/app.rb +++ b/lib/hcl/app.rb @@ -158,7 +158,7 @@ EOM config['login'] = ask("Email Address: ").to_s config['password'] = ask("Password: ") { |q| q.echo = false }.to_s config['subdomain'] = ask("Subdomain: ").to_s - config['ssl'] = %w(y yes).include?(ask("Use SSL? (y/n): ").downcase) + config['ssl'] = /^y/.match(ask("Use SSL? (y/n): ").downcase) TimesheetResource.configure config write_config config end diff --git a/lib/hcl/commands.rb b/lib/hcl/commands.rb index 024d595..e9fd847 100644 --- a/lib/hcl/commands.rb +++ b/lib/hcl/commands.rb @@ -5,6 +5,12 @@ module HCl module Commands class Error < StandardError; end + # Display a sanitized view of your auth credentials. + def config + TimesheetResource.config_hash.merge(password:'***'). + map {|k,v| "#{k}: #{v}" }.join("\n") + end + def tasks project_code=nil tasks = Task.all if tasks.empty? # cache tasks diff --git a/lib/hcl/timesheet_resource.rb b/lib/hcl/timesheet_resource.rb index 1b2fefd..8fa7f5c 100644 --- a/lib/hcl/timesheet_resource.rb +++ b/lib/hcl/timesheet_resource.rb @@ -24,7 +24,8 @@ module HCl end # configuration accessors - %w[ login password subdomain ssl ].each do |config_var| + CONFIG_VARS = [ :login, :password, :subdomain, :ssl ].freeze + CONFIG_VARS.each do |config_var| class_eval <<-EOC def self.#{config_var}= arg @@#{config_var} = arg @@ -35,6 +36,11 @@ module HCl EOC end + # @return [Hash] + def self.config_hash + CONFIG_VARS.inject({}) {|c,k| c.update(k => TimesheetResource.send(k)) } + end + def initialize params @data = params end |
