Class: TodoLint::Cli

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

Overview

Here we bring together all the pieces and see if it comes together

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Cli

Startup the thing that actually checks the files for todos!

Examples:

Cli.new(["-i", ".rb,.js"])


10
11
12
13
14
15
16
17
18
19
# File 'lib/todo_lint/cli.rb', line 10

def initialize(args) # rubocop:disable
  @options = Options.new.parse(args)
  if @options[:config_file]
    @options.merge!(ConfigFile.new.read_config_file(@options[:config_file]))
  elsif File.exist?("./.todo_lint.yml")
    @options.merge!(ConfigFile.new.read_config_file("./.todo_lint.yml"))
  end
  @path = File.expand_path(".")
  add_default_extensions unless @options.fetch(:files, []).any?
end

Instance Method Details

#load_files(file_finder) ⇒ Array<String>

Loads the files to be read

Examples:

cli.load_files(file_finder)

Returns:

  • (Array<String>)


39
40
41
42
43
44
45
# File 'lib/todo_lint/cli.rb', line 39

def load_files(file_finder)
  if file_finder.options.fetch(:files).empty?
    file_finder.list(*options[:extensions])
  else
    file_finder.options.fetch(:files, [])
  end
end

#run!Object

Perform the actions requested based on the options specified

Examples:

Cli.new(["-i", ".rb"]).run!

Returns:

  • exit code 0 for success, 1 for failure



27
28
29
30
31
32
33
# File 'lib/todo_lint/cli.rb', line 27

def run!
  if options[:report]
    print_report
  else
    lint_codebase
  end
end