Class: Forward::Command::Account
- Inherits:
-
Base
- Object
- Base
- Forward::Command::Account
show all
- Defined in:
- lib/forward/command/account.rb
Constant Summary
Forward::Common::EMAIL_REGEX
Instance Attribute Summary
Attributes inherited from Base
#args, #options
Instance Method Summary
collapse
Methods inherited from Base
#initialize, run
#config, #exit_with_error, #exit_with_message, #logged_in?, #logger, #os, #stop_reactor_and_exit, #windows?
Instance Method Details
#default ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/forward/command/account.rb', line 51
def default
config.create_or_load
subdomain = @args.first
if config.accounts.empty?
exit_with_message "You aren't logged into any accounts"
elsif subdomain && config.accounts.has_key?(subdomain.to_sym)
config.create_or_load
config.set_default_account!(subdomain.to_sym)
exit_with_message "#{subdomain} is now your default account"
else
exit_with_message "You're not logged into that account. You can login with: `forward account:login'"
end
rescue ConfigError => e
exit_with_error(e.message)
end
|
#list ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/forward/command/account.rb', line 36
def list
config.create_or_load
if config.accounts.empty?
exit_with_message("You're not logged into any accounts. You can login with: `forward account:login'")
else
puts "Currently logged into:"
config.accounts.keys.sort.each do |subdomain|
default = config.default_account.to_sym == subdomain.to_sym
puts default ? HighLine.color(" - #{subdomain} (default)", :green) : " - #{subdomain}"
end
exit_with_message
end
end
|
#login ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/forward/command/account.rb', line 4
def login
config.create_or_load
email = @args.first
email, password = ask_for_credentials(email)
logger.debug("[API] logging in user: `#{email}:#{password.gsub(/./, 'x')}'")
client do
API::User.authenticate(email, password) do |subdomain, token|
config.add_account(subdomain, token)
exit_with_message "`#{subdomain}' is now logged in and set to the default account"
end
end
end
|
#logout ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/forward/command/account.rb', line 19
def logout
config.create_or_load
subdomain = @args.first
if config.accounts.empty?
exit_with_message "You aren't logged into any accounts"
elsif subdomain
config.remove_account!(subdomain)
exit_with_message "You are now logged out of the '#{subdomain}' account"
else
message = "You must provide a subdomain to logout of an account, you're currently logged into:\n"
message << config.accounts.map { |s, _| " - #{s}" }.join("\n")
exit_with_message message
end
end
|