Skip to content

Commit 034dcfd

Browse files
author
Gopal Adhikari
committed
Fix loading setting and throw appropriate error
1 parent 93d1151 commit 034dcfd

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

bin/argonaut

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ require 'optparse'
1313

1414
# By default show user's reservations if no arguments are supplied
1515
options = { action: 'list_reservations' }
16-
17-
options.merge! Argonaut::Settings.read_config['options']
16+
options.merge! Argonaut::Settings.config[:options]
1817

1918
begin
2019
OptionParser.new do |opts|

lib/argonaut/gateway.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class Gateway
77

88
attr_reader :api_token
99
attr_reader :url_root
10+
ERROR_MESSAGE = 'Could not load settings file ~/.argonaut.yml'.freeze
1011

1112
# Initializes the HTTP gateway to connect to argonaut's API endpoint
1213
# The consumer of this API can supply an API token and
@@ -43,12 +44,15 @@ def config
4344
}
4445

4546
if ENV['ARGONAUT_API_TOKEN'].nil?
46-
raise Argonaut::Exceptions::InvalidConfigurationError.new 'Could not get API token required to connect to Argonaut'
47+
raise Argonaut::Exceptions::InvalidConfigurationError.new ERROR_MESSAGE
4748
end
4849

4950
if ENV['ARGONAUT_URL_ROOT'].nil?
50-
raise Argonaut::Exceptions::InvalidConfigurationError.new 'Could not get Argonaut URL root'
51+
raise Argonaut::Exceptions::InvalidConfigurationError.new ERROR_MESSAGE
5152
end
53+
rescue Argonaut::Exceptions::InvalidConfigurationError => ice
54+
puts ice.message
55+
exit(2)
5256
end
5357

5458
def url_from_path(path)

lib/argonaut/settings.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def self.config
77
private_class_method
88

99
def self.read_config
10-
YAML.load_file("#{Dir.home}/.argonaut.yml")
10+
YAML.load_file("#{Dir.home}/.argonaut.yml").with_indifferent_access
1111
rescue
1212
{ options: {
1313
colorize_rows: true,

0 commit comments

Comments
 (0)