module GitCrecord

Constants

LOGGER
VERSION

Public Class Methods

help() click to toggle source
# File lib/git_crecord.rb, line 48
  def self.help
    puts <<~HELP
      usage: git crecord [<options>]

        -u, --untracked-files  -- show untracked files
        -R, --reverse          -- unstage hunks
        --version              -- show version information
        -h                     -- this help message

        in-program commands:
      #{UI::HelpWindow::CONTENT.gsub(/^/, '  ')}
    HELP
  end
main(argv) click to toggle source
# File lib/git_crecord.rb, line 10
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: untracked_files?(argv), reverse: reverse?(argv))
  end
end
reverse?(argv) click to toggle source
# File lib/git_crecord.rb, line 28
def self.reverse?(argv)
  argv.include?('--reverse') || argv.include?('-R')
end
run(with_untracked_files: false, reverse: false) click to toggle source
# File lib/git_crecord.rb, line 32
def self.run(with_untracked_files: false, reverse: false)
  toplevel_dir = Git.toplevel_dir
  return false if toplevel_dir.empty?

  Dir.chdir(toplevel_dir) do
    files = Diff.create(reverse: reverse, untracked: with_untracked_files)
    return false if files.empty?

    UI::StatusBar.reverse = reverse
    result = UI.run(files)
    return result.call(reverse) == true if result.respond_to?(:call)

    true
  end
end
untracked_files?(argv) click to toggle source
# File lib/git_crecord.rb, line 22
def self.untracked_files?(argv)
  return false if reverse?(argv)

  argv.include?('--untracked-files') || argv.include?('-u')
end