1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2025-02-21 10:20:05 +00:00

fix syntax for variable with multiple conditional

This commit is contained in:
Adrien Waksberg 2017-03-30 19:41:00 +02:00
parent 3c787371b3
commit 755df6c342
3 changed files with 28 additions and 25 deletions

View file

@ -317,19 +317,20 @@ class Cli
# Display the wallet # Display the wallet
# @args: wallet -> the wallet name # @args: wallet -> the wallet name
def get_wallet(wallet = nil) def get_wallet(wallet = nil)
if wallet.to_s.empty? @wallet_file =
wallets = Dir.glob("#{@config.wallet_dir}/*.mpw") if wallet.to_s.empty?
wallets = Dir.glob("#{@config.wallet_dir}/*.mpw")
if wallets.length == 1 if wallets.length == 1
@wallet_file = wallets[0] wallets[0]
elsif !@config.default_wallet.to_s.empty? elsif !@config.default_wallet.to_s.empty?
@wallet_file = "#{@config.wallet_dir}/#{@config.default_wallet}.mpw" "#{@config.wallet_dir}/#{@config.default_wallet}.mpw"
else
"#{@config.wallet_dir}/default.mpw"
end
else else
@wallet_file = "#{@config.wallet_dir}/default.mpw" "#{@config.wallet_dir}/#{wallet}.mpw"
end end
else
@wallet_file = "#{@config.wallet_dir}/#{wallet}.mpw"
end
end end
# Add a new public key # Add a new public key

View file

@ -38,13 +38,14 @@ class Config
def initialize(config_file = nil) def initialize(config_file = nil)
@config_file = config_file @config_file = config_file
if /darwin/ =~ RUBY_PLATFORM @config_dir =
@config_dir = "#{Dir.home}/Library/Preferences/mpw" if /darwin/ =~ RUBY_PLATFORM
elsif /cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM "#{Dir.home}/Library/Preferences/mpw"
@config_dir = "#{Dir.home}/AppData/Local/mpw" elsif /cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM
else "#{Dir.home}/AppData/Local/mpw"
@config_dir = "#{Dir.home}/.config/mpw" else
end "#{Dir.home}/.config/mpw"
end
@config_file = "#{@config_dir}/mpw.cfg" if @config_file.nil? || @config_file.empty? @config_file = "#{@config_dir}/mpw.cfg" if @config_file.nil? || @config_file.empty?
end end

View file

@ -308,14 +308,15 @@ class MPW
# Generate a random password # Generate a random password
# @args: options -> :length, :special, :alpha, :numeric # @args: options -> :length, :special, :alpha, :numeric
# @rtrn: a random string # @rtrn: a random string
def self.password(options = {}) def self.password(**options)
if !options.include?(:length) || options[:length].to_i <= 0 length =
length = 8 if !options.include?(:length) || options[:length].to_i <= 0
elsif options[:length].to_i >= 32768 8
length = 32768 elsif options[:length].to_i >= 32_768
else 32_768
length = options[:length].to_i else
end options[:length].to_i
end
chars = [] chars = []
chars += [*('!'..'?')] - [*('0'..'9')] if options[:special] chars += [*('!'..'?')] - [*('0'..'9')] if options[:special]