Class: ConsoleApp

Inherits:
Object
  • Object
show all
Defined in:
lib/models/console_app.rb

Direct Known Subclasses

Notes

Instance Method Summary collapse

Instance Method Details

#runObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/models/console_app.rb', line 4

def run
  arg = ARGV[0] || ''
  OptionParser.new do |opts|
    opts.banner = 'Usage: notes [options]'
    opts.separator('')
    opts.separator('Options:')
    opts.separator('    [FILE-GLOB]                      Open the first file that matches FILE-GLOB if supplied')
    opts.on('-s', '--search REGEX', 'Search within notes') do |regex|
      self.search(regex)
      exit(0)
    end
    opts.on('-f', '--find FILE-GLOB', 'Find notes that match FILE-GLOB') do |glob|
      puts(self.find(glob))
      exit(0)
    end
    opts.on('-l', '--list [PATH]', 'List all notes', '  (list notes under PATH if supplied)') do |path|
      puts(self.list(path))
      exit(0)
    end
    opts.on('-h', '--help', 'Show this message') do
      puts(opts)
      exit(0)
    end
  end.parse!
  self.on_run(arg)
end