lib/cifrado/cli.rb in cifrado-0.1.3 vs lib/cifrado/cli.rb in cifrado-0.2.0
- old
+ new
@@ -56,11 +56,21 @@
client.test_connection
client
end
def check_options
- config_file = options[:config] || File.join(ENV['HOME'], '.config/cifrado/cifradorc')
+ config_dir = Cifrado::Config.instance.config_dir
+ config_file = options[:config] || File.join(config_dir, 'cifradorc')
+
+ # Cifrado can use config shortcuts, i.e. myhost without path
+ # is equivalent to ~/.config/cifrado/cifradorc.myhost
+ #
+ config_shortcut = File.join(config_dir, "cifradorc.#{config_file}")
+ if File.exist?(config_shortcut)
+ config_file = config_shortcut
+ end
+
config = {}
if File.exist?(config_file)
begin
Log.debug "Configuration file found: #{config_file}"
@@ -70,10 +80,12 @@
original_config = config.dup
rescue => e
Cifrado::Log.error "Error loading config file"
raise e
end
+ else
+ Log.warn "Config file #{config_file} not found."
end
config[:username] = options[:username] || config[:username]
config[:password] = options[:password] || config[:password]
config[:auth_url] = options[:auth_url] || config[:auth_url]
@@ -123,35 +135,7 @@
require 'cifrado/cli/set_acl'
require 'cifrado/cli/jukebox'
require 'cifrado/cli/cinema'
require 'cifrado/cli/saio'
require 'cifrado/cli/version'
+require 'cifrado/cli/configs'
-at_exit do
- include Cifrado::Utils
- include Cifrado
- e = $!
- if e
- if e.is_a? Excon::Errors::Unauthorized
- Log.error "Unauthorized"
- Log.error "Double check the username, password and auth_url."
- elsif e.is_a? Excon::Errors::SocketError
- if e.message =~ /Unable to verify certificate|hostname (was|does) not match (with )?the server/
- Log.error "Unable to verify SSL certificate."
- Log.error "If the server is using a self-signed certificate, try using --insecure."
- Log.error "Please be aware of the security implications."
- else
- Log.error e.message
- end
- elsif e.is_a? RuntimeError
- Log.error e.message
- elsif e.is_a? Interrupt
- Log.info
- Log.info 'At your command, Sir!'
- else
- Log.fatal e.message
- end
- system 'stty echo'
- prettify_backtrace e
- exit! 1
- end
-end