Class: Reviewer::Arguments

Inherits:
Object
  • Object
show all
Defined in:
lib/reviewer/arguments.rb,
lib/reviewer/arguments/tags.rb,
lib/reviewer/arguments/files.rb,
lib/reviewer/arguments/keywords.rb

Overview

Handles option parsing for ‘rvw` and `fmt` commands

Examples:


`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`

Defined Under Namespace

Classes: Files, Keywords, Tags

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = ARGV) ⇒ self

A catch all for aguments passed to reviewer via the command-line so they can be interpreted

and made available via the relevant classes.

Examples:

Using all options: ‘rvw keyword_one keyword_two –files ./example.rb,./example_test.rb –tags syntax`

reviewer = Reviewer::Arguments.new
reviewer.files.to_a # => ['./example.rb','./example_test.rb']
reviewer.tags.to_a # => ['syntax']
reviewer.keywords.to_a # => ['keyword_one', 'keyword_two']

Parameters:

  • options (defaults to: ARGV)

    ARGV [Hash] options to parse and extract the relevant values for a run


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/reviewer/arguments.rb', line 37

def initialize(options = ARGV)
  @output = Output.new
  @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
      @output.help VERSION
      exit
    end

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

Instance Attribute Details

#optionsObject

Returns the value of attribute options.


22
23
24
# File 'lib/reviewer/arguments.rb', line 22

def options
  @options
end

#outputObject (readonly)

Returns the value of attribute output.


24
25
26
# File 'lib/reviewer/arguments.rb', line 24

def output
  @output
end

Instance Method Details

#filesArguments::Files

The file arguments collected from the command line via the ‘-f` or `–files` flag

Returns:

  • (Arguments::Files)

    an collection of the file arguments collected from the command-line


77
78
79
# File 'lib/reviewer/arguments.rb', line 77

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

#keywordsArguments::Keywords

The leftover arguments collected from the command line without being associated with a flag

Returns:


84
85
86
# File 'lib/reviewer/arguments.rb', line 84

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

#tagsArguments::Tags

The tag arguments collected from the command line via the ‘-t` or `–tags` flag

Returns:

  • (Arguments::Tags)

    an colelction of the tag arguments collected from the command-line


70
71
72
# File 'lib/reviewer/arguments.rb', line 70

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

#to_hHash Also known as: inspect

Converts the arguments to a hash for versatility

Returns:

  • (Hash)

    The files, tags, and keywords collected from the command line options


58
59
60
61
62
63
64
# File 'lib/reviewer/arguments.rb', line 58

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