Class: Rbnotes::Commands::Show

Inherits:
Command
  • Object
show all
Defined in:
lib/rbnotes/commands/show.rb

Overview

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.

Instance Method Summary collapse

Instance Method Details

#descriptionObject

:nodoc:



16
17
18
# File 'lib/rbnotes/commands/show.rb', line 16

def description             # :nodoc:
  "Show the content of notes"
end

#execute(args, conf) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 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, conf)
  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

#helpObject

:nodoc:



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/rbnotes/commands/show.rb', line 51

def help                    # :nodoc:
  puts <<HELP
usage:
#{Rbnotes::NAME} show [OPTIONS] [STAMP_PATTERN|KEYWORD...]

Show the content of given notes.  It accepts timestamp patterns and
keywords like the `list` (or `pick`) command.  See the help for the
`list` command to know more about stamp patterns and keywords.

OPTIONS:
-n, --num-of-lines NUMBER
-r, --raw

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

Also accepts `-r` (or `--raw`) option to specify to use "raw" output,
which means no use any pager, no apply to any process to make output.
The behavior is intended to be used within a pipeline.

The command try to read its argument from the standard input when no
argument was passed in the command line.
HELP
end