lib/rouge/cli.rb in rouge-3.23.0 vs lib/rouge/cli.rb in rouge-3.24.0

- old
+ new

@@ -42,10 +42,11 @@ yield %|usage: rougify {global options} [command] [args...]| yield %|| yield %|where <command> is one of:| yield %| highlight #{Highlight.desc}| + yield %| debug #{Debug.desc}| yield %| help #{Help.desc}| yield %| style #{Style.desc}| yield %| list #{List.desc}| yield %| guess #{Guess.desc}| yield %| version #{Version.desc}| @@ -102,10 +103,12 @@ Version when 'help', nil Help when 'highlight', 'hi' Highlight + when 'debug' + Debug when 'style' Style when 'list' List when 'guess' @@ -213,11 +216,11 @@ else ENV['TERM'] !~ /(^rxvt)|(-color$)/ end end - def self.parse(argv) + def self.parse_opts(argv) opts = { :formatter => supports_truecolor? ? 'terminal-truecolor' : 'terminal256', :theme => 'thankful_eyes', :css_class => 'codehilite', :input_file => '-', @@ -254,13 +257,17 @@ else opts[:input_file] = arg end end - new(opts) + opts end + def self.parse(argv) + new(parse_opts(argv)) + end + def input_stream @input_stream ||= FileReader.new(@input_file) end def input @@ -339,9 +346,32 @@ private_class_method def self.parse_cgi(str) pairs = CGI.parse(str).map { |k, v| [k.to_sym, v.first] } Hash[pairs] + end + end + + class Debug < Highlight + def self.desc + end + + def self.doc + return enum_for(:doc) unless block_given? + + yield %|usage: rougify debug [<options>]| + yield %|| + yield %|Debug a lexer. Similar options to `rougify highlight`, but| + yield %|defaults to the `null` formatter, and ensures the `debug`| + yield %|option is enabled, to print debugging information to stdout.| + end + + def self.parse_opts(argv) + out = super(argv) + out[:lexer_opts]['debug'] = '1' + out[:formatter] = 'null' + + out end end class Style < CLI def self.desc