lib/rouge/cli.rb in rouge-0.2.0 vs lib/rouge/cli.rb in rouge-0.2.1
- old
+ new
@@ -15,11 +15,11 @@
if argv.include? '-v' or argv.include? '--version'
puts Rouge.version
exit 0
end
- unless %w(highlight style).include?(argv.first)
+ unless %w(highlight style list --help -h help).include?(argv.first)
argv.unshift 'highlight'
end
super(argv, *a)
end
@@ -28,11 +28,11 @@
option :input_file, :aliases => '-i', :desc => 'the file to operate on'
option :lexer, :aliases => '-l',
:desc => ('Which lexer to use. If not provided, rougify will try to ' +
'guess based on --mimetype, the filename, and the file ' +
'contents.')
- option :formatter, :aliases => '-f', :default => 'html',
+ option :formatter, :aliases => '-f', :default => 'terminal256',
:desc => ('Which formatter to use.')
option :mimetype, :aliases => '-m',
:desc => ('a mimetype that Rouge will use to guess the correct lexer. ' +
'This is ignored if --lexer is specified.')
option :lexer_opts, :aliases => '-L', :type => :hash, :default => {},
@@ -67,9 +67,25 @@
def style(theme_name='thankful_eyes')
theme = Theme.find(theme_name)
raise "unknown theme: #{theme_name}" unless theme
puts theme.new(options).render
+ end
+
+ desc 'list', 'list the available lexers, formatters, and styles'
+ def list
+ puts "== Available Lexers =="
+ all_lexers = Lexer.all
+ max_len = all_lexers.map { |l| l.tag.size }.max
+
+ Lexer.all.each do |lexer|
+ desc = "#{lexer.desc}"
+ if lexer.aliases.any?
+ desc << " [aliases: #{lexer.aliases.join(',')}]"
+ end
+ puts "%s: %s" % [lexer.tag, desc]
+ puts
+ end
end
private
# TODO: does Thor do this for me?
def normalize_hash_keys(hash)