Permalink
Browse files

explaining regexes in print_options

  • Loading branch information...
1 parent 33d218b commit 7621f54b055d51c1714ad06aa19f641717749f9d @alphabetum alphabetum committed Nov 2, 2009
Showing with 7 additions and 1 deletion.
  1. +7 −1 lib/rbst.rb
View
@@ -39,12 +39,18 @@ def to_latex
convert(:latex)
end
- def print_options(format) # :nodoc:
+ # Formats and prints the options from the docutils help in the way they'd be specified in RbST: strings, symbols and hashes.
+ def print_options(format)
help = execute("python #{RbST.executable(format)} --help")
+ # non-hyphenated long options to symbols
help.gsub!(/(\-\-)([A-Za-z0-9]+)([=|\s])/, ':\2\3')
+ # hyphenated long options to quoted strings
help.gsub!(/(\-\-)([\w|\-]+)(\n)?[^$|^=|\]]?/, '\'\2\'\3')
+ # equal to hashrocket
help.gsub!(/\=/, ' => ')
+ # hort options to symbols
help.gsub!(/([^\w])\-(\w)([^\w])/, '\1:\2\1')
+ # short options with args get a hashrocket
help.gsub!(/(:\w) </, '\1 => <')
puts help
end

0 comments on commit 7621f54

Please sign in to comment.