29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/ayadn/switch.rb', line 29
def switch(user)
if user.empty? || user.nil?
puts "\n\nOops, something went wrong, I couldn't get your username. Please try again.\n\n".color(:red)
exit
end
username = Workers.new.remove_arobase_if_present([user.first])[0]
home_path = Dir.home + "/ayadn"
if File.exist?("#{home_path}/accounts.db")
accounts_db = Databases.init("#{home_path}/accounts.db")
active = accounts_db['ACTIVE']
if username == accounts_db[active][:username]
puts "\nYou're already authorized with username '#{accounts_db[active][:handle]}'.\n".color(:red)
cancel(accounts_db)
end
if accounts_db[username]
puts "\nSwitching to account @#{username}...".color(:green)
accounts_db['ACTIVE'] = username
close_db(accounts_db)
puts Status.done
exit
else
puts "\nThis account isn't in the database. Please run 'ayadn authorize'.\n".color(:red)
cancel(accounts_db)
end
else
please
end
end
|