Class: FaaStRuby::Command::Account::Login

Inherits:
AccountBaseCommand show all
Defined in:
lib/faastruby/cli/commands/account/login.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AccountBaseCommand

#password_is_confirmed?, #password_is_valid?, #prompt, #prompt_for_password, #prompt_to_confirm_password

Methods inherited from BaseCommand

#has_user_logged_in?, #help, #load_credentials, #load_yaml, #say, spin, #spin, #write_file

Constructor Details

#initialize(args) ⇒ Login

Returns a new instance of Login.



7
8
9
10
11
12
# File 'lib/faastruby/cli/commands/account/login.rb', line 7

def initialize(args)
  @args = args
  parse_options
  @email = @options['email']
  @password = @options['password']
end

Class Method Details

.helpObject



52
53
54
# File 'lib/faastruby/cli/commands/account/login.rb', line 52

def self.help
  "login [ARGS]"
end

Instance Method Details

#ask_for_emailObject



25
26
27
28
# File 'lib/faastruby/cli/commands/account/login.rb', line 25

def ask_for_email
  print "Email: "
  @email = STDIN.gets.chomp
end

#ask_for_passwordObject



30
31
32
33
34
# File 'lib/faastruby/cli/commands/account/login.rb', line 30

def ask_for_password
  print "Password: "
  @password = STDIN.noecho(&:gets).chomp
  puts "\n"
end

#migrateObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/faastruby/cli/commands/account/login.rb', line 36

def migrate
  old_credentials = File.expand_path("~/.faastruby.tor1")
  return unless File.file?(old_credentials)
  puts "ATTENTION: I've detected you have workspace credentials saved in '#{old_credentials}'.".red
  puts "You need to migrate these credentials into your account."
  print "Do you want to do it right now? [Y/n] "
  answer = STDIN.gets.chomp
  if answer == 'n'
    puts "You won't be able to manage these workspaces until you perform this migration."
    puts "When you are ready to perform this migration, run 'faastruby migrate-workspaces'."
    exit 0
  else
    exec("faastruby migrate-workspaces")
  end
end

#runObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/faastruby/cli/commands/account/login.rb', line 14

def run
  ask_for_email unless @email
  ask_for_password unless @password
  user = User.new(email: @email, password: @password)
  user.
  FaaStRuby::CLI.error(user.errors) if user&.errors.any?
  user.save_credentials
  puts "Login successful."
  migrate
end

#usageObject



56
57
58
59
60
61
62
# File 'lib/faastruby/cli/commands/account/login.rb', line 56

def usage
  puts "Usage: faastruby #{self.class.help}"
  puts %(
-e,--email EMAIL         # Your email
-p,--password PASSWORD   # Your password
  )
end