Class: Commitlint::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/commitlint/cli.rb

Overview

Cli class is responsible for handling command line arguments

Constant Summary collapse

<<~HELP.freeze
  Commintlint v#{Commitlint::VERSION} - A CLI tool to lint commit messages with Conventional Commits.

  Usage: commitlint --message [commit_message | filepath]

  Examples:
    commitlint --message "feat: add new feature"
    commitlint --message "./path/to/commit_msg"
    commitlint --message ".git/COMMIT_EDITMSG"

  Options:
HELP

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Cli

Returns a new instance of Cli.



21
22
23
24
25
26
27
# File 'lib/commitlint/cli.rb', line 21

def initialize(argv)
  @argv = argv
  @options = {
    message: nil,
    quiet: false
  }
end

Class Method Details

.start(argv) ⇒ Object



29
30
31
# File 'lib/commitlint/cli.rb', line 29

def self.start(argv)
  new(argv).run
end

Instance Method Details

#runObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/commitlint/cli.rb', line 33

def run
  @argv << "-h" if @argv.empty?
  parse_options!

  return 0 if @options[:message].nil?

  message = parse_input(@options[:message])
  linter = Linter.new(message, output: !@options[:quite])

  linter.lint!
end