43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/ayadn/switch.rb', line 43
def switch(user)
if user.empty? || user.nil?
@status.no_username
exit
end
username = Workers.new.remove_arobase_if_present([user.first])[0]
please if @acc_db.blank?
accounts = Databases.all_accounts(@acc_db)
please if accounts.empty?
active = accounts.select { |acc| acc[4] == 1 }[0]
active_user = active[0]
if username == active_user
@status.say do
@status.say_green :done, "already authorized with username @#{username}"
end
exit
end
flag = accounts.select { |acc| acc[0] == username }.flatten
if flag.empty?
@status.say do
@status.say_error "@#{username} isn't in the database"
@status.say_yellow :next, "please run `ayadn -auth` to authorize this account"
end
exit
else
@status.say do
@status.say_cyan :switching, "from @#{active_user} to @#{username}"
Databases.set_active_account(@acc_db, username)
@status.say_green :done, "@#{username} is now the active account"
end
exit
end
end
|