bin/trocla in trocla-0.3.0 vs bin/trocla in trocla-0.4.0
- old
+ new
@@ -97,36 +97,53 @@
options.merge(YAML.load(options.delete(:other_options).shift.to_s)||{})
), 0 ]
end
def delete(options)
- [ Trocla.new(options.delete(:config_file)).delete_password(
+ res = Trocla.new(options.delete(:config_file)).delete_password(
options.delete(:trocla_key),
options.delete(:trocla_format)
- ), 0 ]
+ )
+ [ res, res.nil? ? 1 : 0 ]
end
def formats(options)
- "Available formats: #{Trocla::Formats.all.join(', ')}"
+ key = (options.delete(:trocla_key) || '' )
+ if key.empty?
+ "Available formats: #{Trocla::Formats.all.join(', ')}"
+ else
+ res = Trocla.new(options.delete(:config_file)).available_format(
+ key,
+ options.merge(YAML.load(options.delete(:other_options).shift.to_s)||{})
+ )
+ [ res.nil? ? res : res.join(', '), res.nil? ? 1 : 0 ]
+ end
end
+def search(options)
+ res = Trocla.new(options.delete(:config_file)).search_key(
+ options.delete(:trocla_key)
+ )
+ [ res.nil? ? res : res.join("\n"), res.nil? ? 1 : 0 ]
+end
+
def check_format(format_name)
if format_name.nil?
STDERR.puts 'Missing format, exiting...'
exit 1
elsif !Trocla::Formats.available?(format_name)
STDERR.puts "Error: The format #{format_name} is not available"
exit 1
end
end
-actions=['create','get','set','reset','delete', 'formats' ]
+actions=['create','get','set','reset','delete','formats','search']
if (action=ARGV.shift) && actions.include?(action)
options[:trocla_key] = ARGV.shift
options[:trocla_format] = ARGV.shift
options[:other_options] = ARGV
- check_format(options[:trocla_format]) unless ['delete','formats'].include?(action)
+ check_format(options[:trocla_format]) unless ['delete','formats','search'].include?(action)
begin
result, excode = send(action,options)
if result
puts result.is_a?(String) ? result : result.inspect
end