class Git::Lint::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/lint/cli.rb, line 17
def self.configuration
  defaults = Analyzers::Abstract.descendants.reduce({}) do |settings, analyzer|
    settings.merge analyzer.id => analyzer.defaults
  end

  Runcom::Config.new "#{Identity::NAME}/configuration.yml", defaults: defaults
end
new(args = [], options = {}) click to toggle source
Calls superclass method
# File lib/git/lint/cli.rb, line 25
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

analyze() click to toggle source
# File lib/git/lint/cli.rb, line 63
def analyze
  # FIX: Need to accept SHAs.
  # collector = analyze_commits options.commits
  collector = analyze_commits
  abort if collector.errors?
rescue Errors::Base => error
  abort colorizer.red("#{Identity::LABEL}: #{error.message}")
end
config() click to toggle source
# File lib/git/lint/cli.rb, line 46
def config
  path = configuration.current

  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/lint/cli.rb, line 93
def help task = nil
  say and super
end
hook() click to toggle source
# File lib/git/lint/cli.rb, line 75
def hook
  if options.commit_message?
    check_commit_message options.commit_message
  else
    help "--hook"
  end
rescue Errors::Base, GitPlus::Error => error
  abort colorizer.red("#{Identity::LABEL}: #{error.message}")
end
version() click to toggle source
# File lib/git/lint/cli.rb, line 87
def version
  say Identity::VERSION_LABEL
end

Private Instance Methods

analyze_commits() click to toggle source
# File lib/git/lint/cli.rb, line 101
def analyze_commits
  runner.call.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/lint/cli.rb, line 108
def check_commit_message path
  commit = GitPlus::Repository.new.unsaved Pathname(path)
  collector = runner.call commits: [commit]
  reporter = Reporters::Branch.new collector: collector
  say reporter.to_s
  abort if collector.errors?
end