Sha256: 878dd54ee18df34ee0e7b9ef4010ddb7b58f16465dcda5fe94377780cc2894a4

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

require_relative 'git_crecord/diff'
require_relative 'git_crecord/git'
require_relative 'git_crecord/ui'
require_relative 'git_crecord/ui/help_window'
require_relative 'git_crecord/version'

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: untracked_files?(argv))
    end
  end

  def self.untracked_files?(argv)
    argv.include?('--untracked-files') || argv.include?('-u')
  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>]

  -u, --untracked-files  -- show untracked files
  --version              -- show version information
  -h                     -- this help message

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
git-crecord-1.0.8 lib/git_crecord.rb
git-crecord-1.0.7 lib/git_crecord.rb