Sha256: 6ce8bbcc5cc87bbe16dd6f479afbb8446090e1e991d78394aec513880d2f0b19

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

require_relative 'arguments/keywords'
require_relative 'arguments/files'
require_relative 'arguments/tags'

require 'slop'

module Reviewer
  # Handles option parsing for `rvw` and `fmt` commands
  #
  # @example
  #
  #   `rvw`
  #   `rvw -t ruby`
  #   `rvw -f ./example.rb,./example_test.rb`
  #   `rvw staged`
  #   `rvw --files ./example.rb,./example_test.rb --tags syntax`
  #   `rvw ruby staged`
  #
  class Arguments
    attr_accessor :options

    def initialize(options = ARGV)
      @options = Slop.parse options do |opts|
        opts.array '-f', '--files', 'a list of comma-separated files or paths', delimiter: ',', default: []
        opts.array '-t', '--tags', 'a list of comma-separated tags', delimiter: ',', default: []

        opts.on '-v', '--version', 'print the version' do
          puts VERSION
          exit
        end

        opts.on '-h', '--help', 'print the help' do
          puts opts
          exit
        end
      end
    end

    def inspect
      {
        files: files.raw,
        tags: tags.raw,
        keywords: keywords.raw
      }
    end

    def tags
      @tags ||= Arguments::Tags.new(provided: options[:tags])
    end

    def files
      @files ||= Arguments::Files.new(provided: options[:files])
    end

    def keywords
      @keywords ||= Arguments::Keywords.new(options.arguments)
    end

    def tool_names
      @tool_names ||= keywords.for_tool_names.to_a
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
reviewer-0.1.3 lib/reviewer/arguments.rb