Method: Booker#parse

Defined in:
lib/booker.rb

#parse(args) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/booker.rb', line 37

def parse(args)
  # no args given, show help
  helper if args.none?

  # if arg starts with hyphen, parse option
  parse_opt args if /^-.*/.match(args[0])

  # interpret command
  browsearg = args[0]

  if browsearg.match(/^[0-9]/) # bookmark
    bm = Bookmarks.new('')
    url = bm.bookmark_url(browsearg)
    pexit "Failure:".red + " bookmark #{browsearg} not found", 1 if url.nil?
    puts 'opening bookmark ' + url + '...'
    openweb(wrap(url))
  elsif domain.match(browsearg) # website
    puts 'opening website ' + browsearg + '...'
    openweb(wrap(prep(browsearg)))
  else
    allargs = wrap(args.join(' '))
    puts 'searching ' + allargs + '...'
    search = BConfig.new.searcher
    openweb(Shellwords.escape(search + allargs))
  end
end