Class: Michael::Commands::Auth

Inherits:
Michael::Command show all
Defined in:
lib/michael/commands/auth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Michael::Command

#command, #cursor, #editor, #exec_exist?, #generator, #pager, #pastel, #platform, #screen, #spinner, #which

Constructor Details

#initialize(options) ⇒ Auth

Returns a new instance of Auth.



13
14
15
16
# File 'lib/michael/commands/auth.rb', line 13

def initialize(options)
  @prompt = TTY::Prompt.new
  @options = options
end

Instance Attribute Details

#promptObject (readonly)

Returns the value of attribute prompt.



11
12
13
# File 'lib/michael/commands/auth.rb', line 11

def prompt
  @prompt
end

Instance Method Details

#execute(out: $stdout) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/michael/commands/auth.rb', line 18

def execute(out: $stdout)
  token = read_token
  unless Michael::Models::Github::TokenValidator.token_valid?(token)
    return out.puts 'Specified token is invalid'
  end

  unless Michael::Models::Github::TokenValidator.save_token(token)
    return out.puts 'Failed to save the token'
  end

  out.puts 'Token saved'
end