Class: FaaStRuby::Command::Account::Logout

Inherits:
AccountBaseCommand show all
Defined in:
lib/faastruby/cli/commands/account/logout.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) ⇒ Logout

Returns a new instance of Logout.



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

def initialize(args)
  @args = args
  parse_options
  @credentials_file = NewCredentials::CredentialsFile.new
  @credentials = @credentials_file.get
end

Class Method Details

.helpObject



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

def self.help
  "logout [ARGS]"
end

Instance Method Details

#runObject



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

def run
  user = User.new(@credentials)
  unless user.has_credentials?
    puts "Logout successful."
    exit 0
  end
  user.logout(all: @options['all'])
  FaaStRuby::CLI.error(user.errors) if !@options['force'] && user&.errors.any?
ensure
  @credentials_file.clear
  puts "Logout successful."
end

#usageObject



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

def usage
  puts "Usage: faastruby #{self.class.help}"
  puts %(
-a,--all              # Logout from all machines
-f,--force            # Logout from all machines
  )
end