<commit_before>require_relative 'git_crecord/git'
require_relative 'git_crecord/diff'
require_relative 'git_crecord/ui'
require_relative 'git_crecord/version'
require_relative 'git_crecord/ui/help_window'

module GitCrecord
  def self.main(argv)
    if argv.include?('--version')
      puts VERSION
      true
    elsif argv.include?('--help') || argv.include?('-h')
      help
      true
    else
      run(with_untracked_files: !argv.include?('--no-untracked-files'))
    end
  end

  def self.run(with_untracked_files: false)
    Dir.chdir(Git.toplevel_dir) do
      files = Diff.parse(Git.diff)
      files.concat(Diff.untracked_files(Git.status)) if with_untracked_files
      return false if files.empty?
      result = UI.run(files)
      return result.call == true if result.respond_to?(:call)
      true
    end
  end

  def self.help
    puts <<EOS
usage: git crecord [<options>]'

  --no-untracked-files  -- ignore untracked files
  --version             -- show version information'
  -h                    -- this help message'

  in-program commands:'
#{UI::HelpWindow::CONTENT.gsub(/^/, '  ')}
EOS
  end
end
<commit_msg>Fail nicely, if outside of a git repository<commit_after>require_relative 'git_crecord/git'
require_relative 'git_crecord/diff'
require_relative 'git_crecord/ui'
require_relative 'git_crecord/version'
require_relative 'git_crecord/ui/help_window'

module GitCrecord
  def self.main(argv)
    if argv.include?('--version')
      puts VERSION
      true
    elsif argv.include?('--help') || argv.include?('-h')
      help
      true
    else
      run(with_untracked_files: !argv.include?('--no-untracked-files'))
    end
  end

  def self.run(with_untracked_files: false)
    toplevel_dir = Git.toplevel_dir
    return false if toplevel_dir.empty?
    Dir.chdir(toplevel_dir) do
      files = Diff.parse(Git.diff)
      files.concat(Diff.untracked_files(Git.status)) if with_untracked_files
      return false if files.empty?
      result = UI.run(files)
      return result.call == true if result.respond_to?(:call)
      true
    end
  end

  def self.help
    puts <<EOS
usage: git crecord [<options>]'

  --no-untracked-files  -- ignore untracked files
  --version             -- show version information'
  -h                    -- this help message'

  in-program commands:'
#{UI::HelpWindow::CONTENT.gsub(/^/, '  ')}
EOS
  end
end

{'fraction_non_alphanumeric': 0.11804384485666104, 'fraction_numerical': 0.0, 'mean_word_length': 2.9288079470198674, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '872802', 'n_tokens_mistral': 812, 'n_tokens_neox': 800, 'n_words': 171}