Class: Git::Lint::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/git/lint/cli.rb

Overview

The Command Line Interface (CLI) for the gem.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = [], options = {}, config = {}) ⇒ CLI

Returns a new instance of CLI.



25
26
27
28
29
30
31
32
# 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

Class Method Details

.configurationObject



17
18
19
20
21
22
23
# 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

Instance Method Details

#analyzeObject



63
64
65
66
67
68
69
70
# 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

#configObject



46
47
48
49
50
51
52
53
54
# 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) ⇒ Object



96
97
98
# File 'lib/git/lint/cli.rb', line 96

def help task = nil
  say and super
end

#hookObject



78
79
80
81
82
83
84
85
86
# File 'lib/git/lint/cli.rb', line 78

def hook
  if options.commit_message?
    check_commit_message options.commit_message
  else
    help "--hook"
  end
rescue Errors::Base, GitPlus::Errors::Base => error
  abort colorizer.red("#{Identity::LABEL}: #{error.message}")
end

#versionObject



90
91
92
# File 'lib/git/lint/cli.rb', line 90

def version
  say Identity::VERSION_LABEL
end