bin/trocla in trocla-0.2.3 vs bin/trocla in trocla-0.3.0

- old
+ new

@@ -45,64 +45,66 @@ end end.parse! def create(options) - Trocla.new(options.delete(:config_file)).password( + [ Trocla.new(options.delete(:config_file)).password( options.delete(:trocla_key), options.delete(:trocla_format), options.merge(YAML.load(options.delete(:other_options).shift.to_s)||{}) - ) + ) , 0 ] end def get(options) - Trocla.new(options.delete(:config_file)).get_password( + res = Trocla.new(options.delete(:config_file)).get_password( options.delete(:trocla_key), - options.delete(:trocla_format) + options.delete(:trocla_format), + options.merge(YAML.load(options.delete(:other_options).shift.to_s)||{}) ) + [ res, res.nil? ? 1 : 0 ] end def set(options) if options.delete(:ask_password) require 'highline/import' password = ask('Enter your password: ') { |q| q.echo = 'x' }.to_s pwd2 = ask('Repeat password: ') { |q| q.echo = 'x' }.to_s unless password == pwd2 STDERR.puts 'Passwords did not match, exiting!' - exit 1 + return [ nil, 1 ] end else password = options.delete(:password) || STDIN.read.chomp end format = options.delete(:trocla_format) no_format = options.delete('no_format') trocla = Trocla.new(options.delete(:config_file)) value = if no_format password else - trocla.formats(format).format(password, options.delete(:other_options).shift.to_s) + trocla.formats(format).format(password, (YAML.load(options.delete(:other_options).shift.to_s)||{})) end trocla.set_password( options.delete(:trocla_key), format, value ) - '' + [ '', 0 ] end def reset(options) - Trocla.new(options.delete(:config_file)).reset_password( + [ Trocla.new(options.delete(:config_file)).reset_password( options.delete(:trocla_key), options.delete(:trocla_format), options.merge(YAML.load(options.delete(:other_options).shift.to_s)||{}) - ) + ), 0 ] end def delete(options) - Trocla.new(options.delete(:config_file)).delete_password( + [ Trocla.new(options.delete(:config_file)).delete_password( options.delete(:trocla_key), options.delete(:trocla_format) - ) + ), 0 ] end def formats(options) "Available formats: #{Trocla::Formats.all.join(', ')}" end @@ -123,20 +125,22 @@ options[:trocla_key] = ARGV.shift options[:trocla_format] = ARGV.shift options[:other_options] = ARGV check_format(options[:trocla_format]) unless ['delete','formats'].include?(action) begin - if result = send(action,options) + result, excode = send(action,options) + if result puts result.is_a?(String) ? result : result.inspect end rescue Exception => e unless e.message == 'exit' STDERR.puts "Action failed with the following message: #{e.message}" STDERR.puts '(See full trace by running task with --trace)' end raise e if options[:trace] exit 1 end + exit excode.nil? ? 0 : excode else STDERR.puts "Please supply one of the following actions: #{actions.join(', ')}" STDERR.puts "Use #{$0} --help to get a list of options for these actions" exit 1 end