Sha256: 59669a4d64978ca9d68d296da52daed03086565ea6f55340b33081802a989cb1

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

require_relative "version"

require "optparse"

module Glyptodont
  # Command-line options for the tool
  class Options
    attr_reader :directory, :threshold, :max_age_in_days

    def initialize
      @directory = "."
      @threshold = 10
      @max_age_in_days = 14
      parse
    end

    private

    def parse
      OptionParser.new do |opts|
        opts.banner = "Usage: #{opts.program_name} [options]"

        directory_option(opts)
        threshold_option(opts)
        max_age_in_days_option(opts)
        version_option(opts)
      end.parse!(ARGV)
    end

    def directory_option(opts)
      opts.on("-d", "--directory DIRECTORY", String, "Git repository to search for TODOs (default '.')") do |d|
        @directory = d
      end
    end

    def threshold_option(opts)
      opts.on("-t", "--threshold TODOS", Integer, "Maximum number of TODOs to allow (default 10)") do |t|
        @threshold = t
      end
    end

    def max_age_in_days_option(opts)
      opts.on("-m", "--max-age DAYS", Integer, "Maximum number of days to allow TODOs to stay (default 14)") do |m|
        @max_age_in_days = m
      end
    end

    def version_option(opts)
      opts.on_tail("--version", "Show version") do
        puts VERSION
        exit
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
glyptodont-0.1.0 lib/glyptodont/options.rb