Class: Whitepaper::CLI
- Inherits:
-
Object
- Object
- Whitepaper::CLI
- Defined in:
- lib/whitepaper/cli.rb
Overview
The commandline interface to Whitespace.
Constant Summary collapse
- BANNER =
Usage banner
<<-USAGE USAGE
Class Method Summary collapse
-
.parse_options ⇒ Object
Parse and respond to the command line options.
-
.run ⇒ Object
Executes the command line version of whitespace.
Class Method Details
.parse_options ⇒ Object
Parse and respond to the command line options.
14 15 16 17 18 19 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/whitepaper/cli.rb', line 14 def = {} @opts = OptionParser.new do |opts| opts. = BANNER.gsub(/^ /, '') opts.separator '' opts.separator 'Options:' opts.on('-h', '--help', 'Display this help') do puts opts exit 0 end opts.on('-t', '--by-title KEYWORDS', 'Display the data for the paper with the given KEYWORDS in title') do |title| [:by_title] = title end opts.on('-d', '--download', 'Downloads a pdf of the paper of the paper found') do [:download] = true end opts.on('-p', '--pdf', 'Display a link to the pdf of the paper found') do [:print_pdf_url] = true end opts.on('-n', '--name', 'Display the title of the paper found') do [:print_title] = true end opts.on('-a', '--authors', 'Display the authors of the paper found') do [:print_authors] = true end end @opts.parse! if [:by_title] paper = Whitepaper.find_by_title([:by_title]) if [:print_title] puts paper.title end if [:print_authors] puts paper. end if [:print_pdf_url] unless paper.pdf_urls.empty? puts paper.pdf_urls.first end end unless [:print_title] or [:print_authors] or [:print_pdf_url] puts paper end if [:download] and not paper.pdf_urls.empty? puts "Downloading: " + paper.pdf_urls.first paper.download end else puts @opts end end |