Class: Dri::Commands::FAQ

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

Constant Summary collapse

ExitCommand =
Class.new(StandardError)

Instance Method Summary collapse

Methods inherited from Dri::Command

#add_color, #api_client, #bold, #command, #config, #cursor, #editor, #emoji, #handover_report_path, #initialize, #logger, #ops_token, #pastel, #profile, #prompt, #spinner, #timezone, #token, #username, #verify_config_exists

Constructor Details

This class inherits a constructor from Dri::Command

Instance Method Details

#executeObject

Raises:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dri/commands/faq.rb', line 12

def execute(*)
  root_dir = File.expand_path('../../..', __dir__)
  faq_file = File.join(root_dir, 'faq.yaml')
  faq_data = YAML.load_file(faq_file)

  prompt = TTY::Prompt.new

  choices = faq_data.map { |entry| { name: entry['question'], value: entry['link'] } }

  url = prompt.select("Select a question:", choices)
  raise ExitCommand if url.nil? || url.strip.empty?

  begin
    Launchy.open(url)
  rescue Launchy::Error => e
    puts "Failed to open URL: #{e.message}"
    raise ExitCommand
  end
end