Class: Riven::OptParser
- Inherits:
-
Object
- Object
- Riven::OptParser
- Defined in:
- lib/riven/opt_parser.rb
Overview
Utility class to parse the options and files passed to the riven command
Instance Method Summary collapse
-
#files ⇒ Object
Returns an array of Riven::MarkupFile for each given markdown file.
-
#options ⇒ Object
Parses the options and returns a map with the options and their values.
Instance Method Details
#files ⇒ Object
Returns an array of Riven::MarkupFile for each given markdown file
16 17 18 19 20 21 22 23 24 |
# File 'lib/riven/opt_parser.rb', line 16 public def files file_names = ARGV if file_names.size === 1 && File.directory?(file_names[0]) file_names = Dir["#{file_names[0]}/*.md"].sort end file_names.map { |file| Riven::MarkupFile.new(file) } end |
#options ⇒ Object
Parses the options and returns a map with the options and their values.
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 |
# File 'lib/riven/opt_parser.rb', line 31 public def = { output_file: '', cover_file: '', css_file: '', toc: false, dump_html: false } opt_parser = OptionParser.new do |opts| opts. = 'Usage: riven [OPTIONS] Markdown Files' opts.separator '' opts.separator 'Options' opts.on("-o FILE", "--output=FILE", "File name of the output PDF file") do |output_file| [:output_file] = output_file end opts.on("-s FILE", "--css=FILE", "Path to the custom CSS file") do |css_file| [:css_file] = css_file end opts.on("-c FILE", "--cover=FILE", "Path to the cover MD file") do |cover_file| [:cover_file] = cover_file end opts.on("-t", "--toc", "Enabled the table of contents auto generation") do [:toc] = true end opts.on("-d", "--dump-html", "Dumps the HTML file to STDOUT") do [:dump_html] = true end opts.on('-V', '--version', 'Displays the version') do puts Riven::VERSION.to_s exit end end opt_parser.parse! return end |