Module: Jura::Application

Extended by:
Application
Included in:
Application
Defined in:
lib/jura/application.rb

Instance Method Summary collapse

Instance Method Details

#config_credentials(prompt) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/jura/application.rb', line 44

def config_credentials(prompt)
  email = prompt.ask("Jira account email: ") { |q| q.validate :email }

  has_token = prompt.yes?("Already have your JIRA token?")

  unless has_token
    prompt.say("\nOpening Your default browser")
    prompt.warn("> Warning: If browser does not open, visit")
    prompt.warn("> https://id.atlassian.com/manage-profile/security/api-tokens to obtain your token\n")

    system "open https://id.atlassian.com/manage-profile/security/api-tokens"
  end

  token = prompt.mask("Input your Jira token: ") do|q|
    q.required true
  end

  config = {}

  if Jura::Api::Token.verify?(email, token)
    prompt.say("Logged in as #{email}\n", color: :green)
    prompt.say("Configuration has been saved to " + Utils.paint(Configuration::CONFIG_FILE_PATH, :green) + "\n")

    config = { 'email' => email, 'token' => Base64.urlsafe_encode64("#{email}:#{token}") }

    Jura::Configuration.instance.save_config(config)
  else
    prompt.say("Your token or email is invalid", color: :red)
  end

  config
end

#start(args) ⇒ Object



7
8
9
10
11
12
13
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
# File 'lib/jura/application.rb', line 7

def start(args)
  Readline.completion_append_character = " "

  Readline.completion_proc = lambda { |buffer|
    Command.generate_suggestions(buffer, Readline.line_buffer)
  }

  prompt = TTY::Prompt.new

  prompt.say(Jura::Component::Logo.render)
  prompt.say(Jura::Component::Help.render)

  config = Jura::Configuration.instance.load_config

  if config.empty?
    config = config_credentials(prompt)
  else
    prompt.say("Welcome back!, " + Utils.paint(config['email'], :green) + "\n\n")
    prompt.say("Your selected board is " + Utils.paint(config['selected_board_name'], :green) + "\n\n") unless config['selected_board_id'].nil?
  end

  Jura::Configuration.instance.set_config(config)

  Jura::RootControl.instance.config_commands
  Jura::Control::Sprint.instance.config_commands

  loop do
    command_buffer = Readline.readline("\e[15;48;5;27m Jura Guarrr! \e[0m > ", true)

    Jura::CommandHandler.call(command_buffer.strip())
  rescue IndexError, NoMethodError => _e
    Command::Invalid.execute("Something went wrong, please try with another command")
  end
rescue Interrupt
  Command::Exit.execute!
end