Class: Dri::Commands::Init

Inherits:
Dri::Command show all
Defined in:
lib/dri/commands/init.rb

Instance Attribute Summary

Attributes inherited from Dri::Command

#config, #emoji, #profile, #timezone, #token, #username

Instance Method Summary collapse

Methods inherited from Dri::Command

#add_color, #api_client, #command, #cursor, #editor, #logger, #pastel, #prompt, #spinner, #verify_config_exists

Constructor Details

#initialize(options) ⇒ Init

Returns a new instance of Init.



11
12
13
14
# File 'lib/dri/commands/init.rb', line 11

def initialize(options)
  font = TTY::Font.new(:doom)       
  puts pastel.yellow(font.write("DRI"))
end

Instance Method Details

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



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
# File 'lib/dri/commands/init.rb', line 16

def execute(input: $stdin, output: $stdout)
  output.puts "🤖 Welcome to DRI 🤖\n"

  logger.info "🔎 Scanning for existing configurations...\n"

  if config.exist?
    overwrite = prompt.yes?("There is already a configuration initialized. Would you like to overwrite it?")
    unless overwrite
      output.puts "Using existing configuration. To view configuration in use try  #{add_color('dri profile', :yellow)}."
      exit 0
    end
  end

  @username = prompt.ask("What is your GitLab username?")
  @token = prompt.mask("Please provide your GitLab personal access token:")
  @timezone = prompt.select("Choose your current timezone?", %w(EMEA AMER APAC))
  @emoji = prompt.ask("Have a triage emoji?")

  if (@emoji || @token || @username).nil?
    logger.error "Please provide a username, token, timezone and emoji used for triage."
    exit 1
  end

  config.set(:settings, :user, value: @username)
  config.set(:settings, :token, value: @token)
  config.set(:settings, :timezone, value: @timezone)
  config.set(:settings, :emoji, value: @emoji)
  config.write(force: true)

  logger.success "✅ We're ready to go 🚀"      
end