Class: TempestTime::Commands::Config::Setup

Inherits:
TempestTime::Command show all
Defined in:
lib/tempest_time/commands/config/setup.rb

Instance Method Summary collapse

Methods inherited from TempestTime::Command

#command, #pastel, #prompt, #spinner, #table, #with_spinner, #with_success_fail_spinner

Constructor Details

#initialize(options) ⇒ Setup

Returns a new instance of Setup.



10
11
12
# File 'lib/tempest_time/commands/config/setup.rb', line 10

def initialize(options)
  @options = options
end

Instance Method Details

#execute(input: $stdin, output: $stdout) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/tempest_time/commands/config/setup.rb', line 14

def execute(input: $stdin, output: $stdout)
  email = prompt.ask(
    'Please enter your Atlassian ID. '\
    'This is typically your login email.'
  )
  username = prompt.ask(
    'Please enter your Atlassian username.'
  )
  subdomain = prompt.ask(
    'Please enter your Atlassian subdomain. '\
    'i.e. [THIS VALUE].atlassian.net'
  )
  jira_token = prompt.ask(
    'Please enter your Atlassian API token. '\
    'Your token can be generated at https://id.atlassian.com/manage/api-tokens'
  )
  tempo_token = prompt.ask(
    'Please enter your Tempo API token. '\
    "Your token can be generated through your worksheet's settings page."
  )

  if [email, username, subdomain, jira_token, tempo_token].any?(&:nil?)
    abort(
      pastel.red('Setup failed!') + ' ' +
      'One or more credentials were missing. Please try again.'
    )
  end

  authorization = TempestTime::Settings::Authorization

  authorization.update('email', email)
  authorization.update('username', username)
  authorization.update('subdomain', subdomain)
  authorization.update('jira_token', jira_token)
  authorization.update('tempo_token', tempo_token)

  puts pastel.green('Setup complete!')
end