lib/td/command/common.rb in td-0.10.22 vs lib/td/command/common.rb in td-0.10.23

- old
+ new

@@ -13,18 +13,23 @@ private def initialize @render_indent = '' end - def get_client + def get_client(opts={}) apikey = Config.apikey unless apikey raise ConfigError, "Account is not configured." end - Client.new(apikey) + Client.new(apikey, opts) end + def get_ssl_client(opts={}) + opts[:ssl] = true + get_client(opts) + end + def cmd_render_table(rows, *opts) require 'hirb' Hirb::Helpers::Table.render(rows, *opts) end @@ -92,9 +97,33 @@ end #if type && table.type != type # $stderr.puts "Table '#{db_name}.#{table_name} is not a #{type} table but a #{table.type} table" #end table + end + + def ask_password(max=3, &block) + 3.times do + begin + system "stty -echo" # TODO termios + print "Password (typing will be hidden): " + password = STDIN.gets || "" + password = password[0..-2] # strip \n + rescue Interrupt + $stderr.print "\ncanceled." + exit 1 + ensure + system "stty echo" # TODO termios + print "\n" + end + + if password.empty? + $stderr.puts "canceled." + exit 0 + end + + yield password + end end end end