class Octodown::FileChooser

Constants

EXTENSIONS
TUI

Attributes

logger[R]
prompt[R]

Public Class Methods

new(logger:) click to toggle source
# File lib/octodown/support/file_chooser.rb, line 65
def initialize(logger:)
  @logger = logger
  @prompt = TUI
end

Public Instance Methods

abort_no_files_found!() click to toggle source
# File lib/octodown/support/file_chooser.rb, line 76
def abort_no_files_found!
  prompt.error 'We could not find any markdown files in this folder.'
  puts
  prompt.error 'Try passing the file explicitly such as, i.e:'
  prompt.error '    $ octodown README.md'
  exit 1
end
all_markdown_files() click to toggle source
# File lib/octodown/support/file_chooser.rb, line 84
def all_markdown_files
  choices = MarkdownFileList.new(logger).call

  abort_no_files_found! if choices.empty?

  choices.sort_by! { |c| c.split(File::SEPARATOR).length }
end
call() click to toggle source
# File lib/octodown/support/file_chooser.rb, line 70
def call
  choices = all_markdown_files
  choice = prompt.select('Which file would you like to edit?', choices)
  File.open(choice, 'r')
end