class Rbnotes::Commands::Show

Shows the content of the notes specified by arguments. Arguments should be timestamp patterns or keywords. See the document for the `list` command to know about such arguments.

Accepts an option with `-n NUMBER` (or `–num-of-lines`), to show the first NUMBER lines of the content of each note.

If no argument is passed, reads the standard input for arguments. If a specified timestamp does not exist in the repository as a key, Rbnotes::MissingTimestampError will occur.

Public Instance Methods

execute(args, conf) click to toggle source
# File lib/rbnotes/commands/show.rb, line 20
def execute(args, conf)
  @opts = {}
  parse_opts(args)

  repo = Textrepo.init(conf)
  stamps = read_timestamps(args, repo)
  return if stamps.empty?

  content = stamps.map { |stamp|
    begin
      text = repo.read(stamp)
    rescue Textrepo::MissingTimestampError => _
      raise Rbnotes::MissingTimestampError, stamp
    end

    lines = text.size
    if @opts[:num_of_lines].to_i > 0
      lines = [@opts[:num_of_lines], lines].min
    end

    [stamp, text[0, lines]]
  }.to_h

  pager = conf[:pager]
  unless pager.nil? or @opts[:raw]
    puts_with_pager(pager, make_output(content))
  else
    puts make_output(content)
  end
end