Module: MarkdownUsage
- Defined in:
- lib/markdown_usage.rb,
lib/markdown_usage/version.rb
Constant Summary collapse
- Error =
Class.new(StandardError)
- HEADING =
/\A(\#{1,6})/
- ALT_HEADING =
/\A([-=]+)\s*\Z/
- ALT_HEADING_LEVELS =
{ "=" => 1, "-" => 2 }.freeze
- STACKTRACE =
/\A(.+):\d+:in\s+`(.+)'/
- EXTENSIONS =
%w[md markdown].freeze
- VERSION =
"0.0.1"
Class Method Summary collapse
-
.print(options = nil) ⇒ Object
Print the calling program’s usage based on
options
.
Class Method Details
.print(options = nil) ⇒ Object
Print the calling program’s usage based on options
. See README for a list of options
.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/markdown_usage.rb', line 20 def print( = nil) ||= {} output = [:output] || $stdout exitcode = .include?(:exit) ? [:exit] : 0 raise_errors = .include?(:raise_errors) ? [:raise_errors] : true error("Usage document cannot be found", raise_errors) and return unless defined?(DATA) || [:source] if ![:source] lines = DATA.readlines else source = find_readme([:source], find_root_directory) error("Cannot find usage source: #{[:source]}", raise_errors) and return unless source lines = File.readlines(source) end output.puts TTY::Markdown.parse(extract_usage(lines, [:sections])) exit exitcode unless exitcode == false rescue => e error(e, raise_errors) end |