Skip to content

Commit

Permalink
Add a CLI debug command that provides reasonable defaults (rouge-ruby…
Browse files Browse the repository at this point in the history
…#1593)

This command is identical to highlight, but provides more convenient access to
the debugging features within Rouge.

```shell
# before
rougify -f null -L debug=1 input-file

# after
rougify debug input-file
```
  • Loading branch information
jneen authored Oct 13, 2020
1 parent da6d96c commit b2dcb98
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions lib/rouge/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def self.doc
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}|
Expand Down Expand Up @@ -104,6 +105,8 @@ def self.class_from_arg(arg)
Help
when 'highlight', 'hi'
Highlight
when 'debug'
Debug
when 'style'
Style
when 'list'
Expand Down Expand Up @@ -215,7 +218,7 @@ def self.supports_truecolor?
end
end

def self.parse(argv)
def self.parse_opts(argv)
opts = {
:formatter => supports_truecolor? ? 'terminal-truecolor' : 'terminal256',
:theme => 'thankful_eyes',
Expand Down Expand Up @@ -256,7 +259,11 @@ def self.parse(argv)
end
end

new(opts)
opts
end

def self.parse(argv)
new(parse_opts(argv))
end

def input_stream
Expand Down Expand Up @@ -344,6 +351,29 @@ def self.parse_cgi(str)
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
"print CSS styles"
Expand Down

0 comments on commit b2dcb98

Please sign in to comment.