class TodoLint::Options

Handles option parsing for the command line application.

Attributes

options[R]

Options hash for all configurations @return [Hash] @api private

Public Instance Methods

parse(args) click to toggle source

Parses command line options into an options hash @api public @example Options.new.parse(“todo_lint -c app.rb”) @param args [Array<String>] arguments passed via the command line @return [Hash] parsed options

# File lib/todo_lint/options.rb, line 11
def parse(args)
  @options = { :report => false }

  OptionParser.new do |parser|
    parser.banner = "Usage: todo_lint [options] [files]"
    add_config_options parser
    exclude_file_options parser
    include_extension_options parser
    report_version parser
    report_report_options parser
  end.parse!(args)

  # Any remaining arguments are assumed to be files
  options[:files] = args

  options
end

Private Instance Methods

add_config_options(parser) click to toggle source

Adds the file options to the @options hash @api private @return [Hash]

# File lib/todo_lint/options.rb, line 34
def add_config_options(parser)
  parser.on("-c", "--config config-file", String,
            "Specify the path to the config file you want
             to use, from the main repo") do |conf_file|
    options[:config_file] = conf_file
  end
end
exclude_file_options(parser) click to toggle source

Adds the excluded file options to the options hash @api private @return [Hash]

# File lib/todo_lint/options.rb, line 45
def exclude_file_options(parser)
  parser.on("-e", "--exclude file1,...", Array,
            "List of file names to exclude") do |files_list|
    options[:excluded_files] = []
    files_list.each do |short_file|
      options[:excluded_files] << File.expand_path(short_file)
    end
  end
end
include_extension_options(parser) click to toggle source

Adds the include extension options to the @options hash @api private @return [Hash]

# File lib/todo_lint/options.rb, line 58
def include_extension_options(parser)
  parser.on("-i", "--include ext1,...", Array,
            "List of extensions to include") do |ext_list|
    options[:extensions] = ext_list
  end
end
report_report_options(parser) click to toggle source

Checks if the user requested a report on the todos in their codebase @api private @return [Hash]

# File lib/todo_lint/options.rb, line 78
def report_report_options(parser)
  parser.on("-r", "--report") do
    options[:report] = true
  end
end
report_version(parser) click to toggle source

Reports the current version of the gem and that's it! @api private @return [Hash]

# File lib/todo_lint/options.rb, line 68
def report_version(parser)
  parser.on("-v", "--version") do
    puts VERSION
    exit
  end
end