<commit_before>require 'optparse'
require 'pathname'

module Styles
  class Application
    def run
      create_stylesheets_dir
      parse_args
      create_stylesheets
      process
    end

    private

    attr_accessor :stylesheet_names

    def process
      input_stream, output_stream = $stdin, $stdout

      while line = input_stream.gets
        result = engine.process(line)
        output_stream.puts result if result
      end
    end

    def engine
      @engine ||= Styles::Engine.new(stylesheets)
    end

    def stylesheets
      @stylesheets ||= []
    end

    def parse_args
      OptionParser.new do |opts|
        opts.on('--edit [NAME]', 'Edit stylesheet with given NAME (\'default\' by default)') do |name|
          safe_exec which_editor, stylesheet_file(name ||= 'default')
        end
        opts.on_tail('-h', '--help', 'Show this message') do
          puts opts
          exit
        end
        opts.on_tail('--version', 'Show version') do
          puts "Styles version: #{Styles::VERSION}"
          exit
        end
      end.parse!

      self.stylesheet_names = ARGV.dup
      stylesheet_names << 'default' if stylesheet_names.empty?
    end

    def create_stylesheets
      stylesheet_names.each do |name|
        stylesheets << ::Styles::Stylesheet.from_string(IO.read(stylesheet_file(name)))
      end
    end

    def which_editor
      editor = ENV['STYLES_EDITOR'] || ENV['EDITOR']
      return editor unless editor.nil?

      %w[subl mate].each {|e| return e if which(e) }

      '/usr/bin/vim'
    end

    def which(cmd)
      dir = ENV['PATH'].split(':').find {|p| File.executable? File.join(p, cmd)}
      Pathname.new(File.join(dir, cmd)) unless dir.nil?
    end<commit_msg>Add --list stylesheets feature<commit_after>require 'optparse'
require 'pathname'

module Styles
  class Application
    def run
      create_stylesheets_dir
      parse_args
      read_stylesheets
      process
    end

    private

    def process
      input_stream, output_stream = $stdin, $stdout

      while line = input_stream.gets
        result = engine.process(line)
        output_stream.puts result if result
      end
    end

    def engine
      @engine ||= Styles::Engine.new(stylesheets)
    end

    def stylesheets
      @stylesheets ||= []
    end

    def parse_args
      OptionParser.new do |opts|
        opts.on('--edit [NAME]', 'Edit stylesheet with given NAME (\'default\' by default)') do |name|
          safe_exec which_editor, stylesheet_file(name ||= 'default')
        end
        opts.on('--list', 'List names of available stylesheets') do
          Dir.entries(stylesheets_dir).grep(/\.rb$/).each { |ss| puts ss.sub(/\.rb$/, '') }
          exit
        end
        opts.on_tail('-h', '--help', 'Show this message') do
          puts opts
          exit
        end
        opts.on_tail('--version', 'Show version') do
          puts "Styles version: #{Styles::VERSION}"
          exit
        end
      end.parse!
    end

    def read_stylesheets
      stylesheet_names = ARGV.dup
      stylesheet_names << 'default' if stylesheet_names.empty?
      stylesheet_names.each do |name|
        stylesheets << ::Styles::Stylesheet.from_string(IO.read(stylesheet_file(name)))
      end
    end

    def which_editor
      editor = ENV['STYLES_EDITOR'] || ENV['EDITOR']
      return editor unless editor.nil?

      %w[subl mate].each {|e| return e if which(e) }

      '/usr/bin/vim'
    end

    def which(cmd)
      dir = ENV['PATH'].split(':').find {|p| File.executable? File.join(p, cmd)}
      Pathname.new(File.join(dir, cmd)) unless dir.nil?
    end
{'fraction_non_alphanumeric': 0.11356728378004974, 'fraction_numerical': 0.0, 'mean_word_length': 2.2849364791288567, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1429277', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1103, 'n_words': 281}