<commit_before>module TChart
  
  #
  # Responsible for parsing command line options and arguments.
  #
  class CommandLineParser
    
    def self.parse(argv) # => [ CommandLineArgs, [] ] or [ nil, [ String, ... ] ]
      CommandLineParser.new.parse(argv)
    end
    
    def parse(argv) # => [ CommandLineArgs, [] ] or [ nil, [ String, ... ] ]
      parse_options(argv)
      [ parse_args(argv), [] ]
    rescue TChartError => e
      [ nil, [ e.message ] ]
    end
    
  private
  
    def parse_options(argv)
      argv.map { |arg| arg.strip.downcase }.each do |arg|
        case
        when arg == "-h" || arg == "--help"
          raise_usage
        when arg == "-v" || arg == "--version"
          raise_version
        when arg.start_with?("-")
          raise_usage
        end
      end
    end
    
    def parse_args(argv) # => CommandLineArgs
      parse_options(argv)
      raise_usage unless argv.length == 2<commit_msg>parse_options() erroneously called twice; fixed.<commit_after>module TChart
  
  #
  # Responsible for parsing command line options and arguments.
  #
  class CommandLineParser
    
    def self.parse(argv) # => [ CommandLineArgs, [] ] or [ nil, [ String, ... ] ]
      CommandLineParser.new.parse(argv)
    end
    
    def parse(argv) # => [ CommandLineArgs, [] ] or [ nil, [ String, ... ] ]
      parse_options(argv)
      [ parse_args(argv), [] ]
    rescue TChartError => e
      [ nil, [ e.message ] ]
    end
    
  private
  
    def parse_options(argv)
      argv.map { |arg| arg.strip.downcase }.each do |arg|
        case
        when arg == "-h" || arg == "--help"
          raise_usage
        when arg == "-v" || arg == "--version"
          raise_version
        when arg.start_with?("-")
          raise_usage
        end
      end
    end
    
    def parse_args(argv) # => CommandLineArgs
      raise_usage unless argv.length == 2
{'fraction_non_alphanumeric': 0.13036565977742448, 'fraction_numerical': 0.0010598834128245894, 'mean_word_length': 1.9546165884194053, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '239526', 'n_tokens_mistral': 591, 'n_tokens_neox': 586, 'n_words': 142}