lib/rouge/cli.rb in rouge-2.2.1 vs lib/rouge/cli.rb in rouge-3.0.0

- old
+ new

@@ -11,13 +11,13 @@ end def file case input when '-' - IO.new($stdin.fileno, 'r:utf-8') + IO.new($stdin.fileno, 'rt:bom|utf-8') when String - File.new(input, 'r:utf-8') + File.new(input, 'rt:bom|utf-8') when ->(i){ i.respond_to? :read } input end end @@ -42,10 +42,11 @@ yield %|where <command> is one of:| yield %| highlight #{Highlight.desc}| yield %| help #{Help.desc}| yield %| style #{Style.desc}| yield %| list #{List.desc}| + yield %| guess #{Guess.desc}| yield %| version #{Version.desc}| yield %|| yield %|See `rougify help <command>` for more info.| end @@ -95,10 +96,12 @@ Highlight when 'style' Style when 'list' List + when 'guess' + Guess end end class Version < CLI def self.desc @@ -372,9 +375,40 @@ puts end end end + + class Guess < CLI + def self.desc + "guess the languages of file" + end + + def self.parse(args) + new(input_file: args.shift) + end + + attr_reader :input_file, :input_source + + def initialize(opts) + @input_file = opts[:input_file] || '-' + @input_source = FileReader.new(@input_file).read + end + + def lexers + Lexer.guesses( + filename: input_file, + source: input_source, + ) + end + + def run + lexers.each do |l| + puts "{ tag: #{l.tag.inspect}, title: #{l.title.inspect}, desc: #{l.desc.inspect} }" + end + end + end + private_class_method def self.normalize_syntax(argv) out = [] argv.each do |arg|