bin/trocla in trocla-0.0.7 vs bin/trocla in trocla-0.0.8
- old
+ new
@@ -24,61 +24,57 @@
end
opts.on("--no-random") do
options['random'] = false
end
-
+
opts.on("--length LENGTH") do |v|
options['length'] = v.to_i
end
-
- opts.on("--pwd-from-stdin") do
+
+ opts.on("--password [PASSWORD]", "-p", "Provide password at command line") do |pass|
options[:ask_password] = false
+ options[:password] = pass
end
-
end.parse!
def create(options)
- miss_format unless options[:trocla_format]
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)||{})
)
end
def get(options)
- miss_format unless options[:trocla_format]
Trocla.new(options.delete(:config_file)).get_password(
options.delete(:trocla_key),
options.delete(:trocla_format)
)
end
def set(options)
- miss_format unless options[:trocla_format]
if options.delete(:ask_password)
require 'highline/import'
password = ask("Enter your password: ") { |q| q.echo = "x" }
pwd2 = ask("Repeat password: ") { |q| q.echo = "x" }
unless password == pwd2
STDERR.puts "Passwords did not match, exiting!"
exit 1
end
else
- password = options.delete(:other_options).shift
+ password = options.delete(:password) || STDIN.read.chomp
end
Trocla.new(options.delete(:config_file)).set_password(
options.delete(:trocla_key),
options.delete(:trocla_format),
password
)
""
end
def reset(options)
- miss_format unless options[:trocla_format]
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)||{})
)
@@ -89,20 +85,26 @@
options.delete(:trocla_key),
options.delete(:trocla_format)
)
end
-def miss_format
- STDERR.puts "Missing format, exiting..."
- exit 1
+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']
if !(ARGV.length < 2) && (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 action == 'delete'
begin
if result = send(action,options)
puts result.is_a?(String) ? result : result.inspect
end
rescue Exception => e