Class: Dri::Commands::FAQ
- Inherits:
-
Dri::Command
- Object
- Dri::Command
- Dri::Commands::FAQ
- 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, #cursor, #editor, #initialize, #pastel, #prompt, #spinner, #verify_config_exists
Methods included from Utils::Helpers
Constructor Details
This class inherits a constructor from Dri::Command
Instance Method Details
#execute ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dri/commands/faq.rb', line 11 def execute(*) root_dir = File.('../../..', __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.}" raise ExitCommand end end |