add exceptions parse for OptionParser

This commit is contained in:
Alexander Popov 2022-01-03 23:47:06 +03:00
parent e067e2cb24
commit 5d7fca4096

View File

@ -23,6 +23,7 @@ end
VERSION = "0.1.0" VERSION = "0.1.0"
begin
OptionParser.parse do |parser| OptionParser.parse do |parser|
parser.banner = "Welcome to The Beatles App!" parser.banner = "Welcome to The Beatles App!"
@ -35,16 +36,19 @@ OptionParser.parse do |parser|
exit exit
end end
parser.on "-g", "--generate-password", "Generate password" do parser.on "-g", "--generate-password", "Generate password" do
puts Random::Secure.urlsafe_base64(16, padding: false).to_s.colorize(:black).back(:white) puts Random::Secure.urlsafe_base64(16, padding: false).colorize(:black).back(:white)
puts Random::Secure.urlsafe_base64(16, padding: false).to_s.colorize(:white).back(:red) puts Random::Secure.urlsafe_base64(16, padding: false).colorize(:white).back(:red)
puts Random::Secure.urlsafe_base64(16, padding: false).to_s.colorize(:white).back(:blue) puts Random::Secure.urlsafe_base64(16, padding: false).colorize(:white).back(:blue)
exit exit
end end
parser.on "-t", "--unixtime", "Return local timestamp" do parser.on "-t", "--unixtime", "Return local timestamp" do
puts Time.local.to_unix puts Time.local.to_unix.colorize(:yellow)
exit exit
end end
end end
rescue ex
puts ex.message, ""
end
if !File.exists?("pwd.yml") if !File.exists?("pwd.yml")
puts "No password.yml file exists." puts "No password.yml file exists."
@ -69,13 +73,13 @@ while true
if password_string.to_s == ":q" if password_string.to_s == ":q"
puts "Bye! 👋🏻" puts "Bye! 👋🏻"
exit
exit(0)
elsif password_string.to_s == ":h" elsif password_string.to_s == ":h"
puts "Help:\n-----" puts "Help:\n-----"
puts "\t:s - Return stats" puts ":s - Return stats"
elsif password_string.to_s == ":s" elsif password_string.to_s == ":s"
puts "Statictics:\n----------"
print "Elements: ".colorize(:yellow) print "Elements: ".colorize(:yellow)
puts new_array.size puts new_array.size