class Git::Cop::CLI

The Command Line Interface (CLI) for the gem.

Attributes

colorizer[R]
configuration[R]
runner[R]

Public Class Methods

configuration() click to toggle source
# File lib/git/cop/cli.rb, line 16
def self.configuration
  defaults = Styles::Abstract.descendants.reduce({}) do |settings, cop|
    settings.merge cop.id => cop.defaults
  end

  Runcom::Configuration.new project_name: Identity.name, defaults: defaults
end
new(args = [], options = {}) click to toggle source
Calls superclass method
# File lib/git/cop/cli.rb, line 24
def initialize args = [], options = {}, config = {}
  super args, options, config
  @configuration = self.class.configuration
  @runner = Runner.new configuration: @configuration.to_h
  @colorizer = Pastel.new
rescue Runcom::Errors::Base => error
  abort error.message
end

Public Instance Methods

config() click to toggle source
# File lib/git/cop/cli.rb, line 43
def config
  path = configuration.path

  if options.edit? then `#{ENV["EDITOR"]} #{path}`
  elsif options.info?
    path ? say(path) : say("Configuration doesn't exist.")
  else help(:config)
  end
end
help(task = nil) click to toggle source
Calls superclass method
# File lib/git/cop/cli.rb, line 91
def help task = nil
  say and super
end
hook() click to toggle source
# File lib/git/cop/cli.rb, line 73
def hook
  if options.commit_message?
    check_commit_message options.commit_message
  else
    help "--hook"
  end
rescue Errors::Base => exception
  abort colorizer.red("#{Identity.label}: #{exception.message}")
end
police() click to toggle source
# File lib/git/cop/cli.rb, line 60
def police
  collector = analyze_commits options.commits
  abort if collector.errors?
rescue Errors::Base => exception
  abort colorizer.red("#{Identity.label}: #{exception.message}")
end
version() click to toggle source
# File lib/git/cop/cli.rb, line 85
def version
  say Identity.version_label
end

Private Instance Methods

analyze_commits(shas) click to toggle source
# File lib/git/cop/cli.rb, line 104
def analyze_commits shas
  load_collector(shas).tap do |collector|
    reporter = Reporters::Branch.new collector: collector
    say reporter.to_s
  end
end
check_commit_message(path) click to toggle source
# File lib/git/cop/cli.rb, line 111
def check_commit_message path
  commit = Commits::Unsaved.new path: path
  collector = runner.run commits: commit
  reporter = Reporters::Branch.new collector: collector
  say reporter.to_s
  abort if collector.errors?
end
load_collector(shas) click to toggle source
# File lib/git/cop/cli.rb, line 99
def load_collector shas
  commits = shas.map { |sha| Commits::Saved.new sha: sha }
  commits.empty? ? runner.run : runner.run(commits: commits)
end