Class: Reviewer::Arguments
- Inherits:
-
Object
- Object
- Reviewer::Arguments
- 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
Defined Under Namespace
Classes: Files, Keywords, Tags
Constant Summary collapse
- KNOWN_FORMATS =
Valid output format options for the –format flag
i[streaming summary json].freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
-
#files ⇒ Arguments::Files
The file arguments collected from the command line via the
-for--filesflag. -
#format ⇒ Symbol
The output format for results.
-
#help? ⇒ Boolean
Whether the –help flag was passed.
-
#initialize(options = ARGV, output: Output.new) ⇒ self
constructor
Parses command-line arguments and makes them available as tags, files, and keywords.
-
#json? ⇒ Boolean
Whether to output results as JSON.
-
#keywords ⇒ Arguments::Keywords
The leftover arguments collected from the command line without being associated with a flag.
-
#raw? ⇒ Boolean
Whether to force raw/passthrough output regardless of tool count.
-
#runner_strategy(multiple_tools:) ⇒ Class
Determines the appropriate runner strategy based on CLI flags.
-
#streaming? ⇒ Boolean
Whether output should be streamed directly (not captured for later formatting).
-
#tags ⇒ Arguments::Tags
The tag arguments collected from the command line via the
-tor--tagsflag. -
#to_h ⇒ Hash
(also: #inspect)
Converts the arguments to a hash for versatility.
-
#version? ⇒ Boolean
Whether the –version flag was passed.
Constructor Details
#initialize(options = ARGV, output: Output.new) ⇒ self
Parses command-line arguments and makes them available as tags, files, and keywords.
42 43 44 45 |
# File 'lib/reviewer/arguments.rb', line 42 def initialize( = ARGV, output: Output.new) @output = output = Slop.parse() { |opts| (opts) } end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
27 28 29 |
# File 'lib/reviewer/arguments.rb', line 27 def end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
29 30 31 |
# File 'lib/reviewer/arguments.rb', line 29 def output @output end |
Instance Method Details
#files ⇒ Arguments::Files
The file arguments collected from the command line via the -f or --files flag
96 97 98 99 100 101 102 103 |
# File 'lib/reviewer/arguments.rb', line 96 def files @files ||= Arguments::Files.new( provided: [:files], keywords: keywords.reserved, output: output, on_git_error: session_formatter.method(:git_error) ) end |
#format ⇒ Symbol
The output format for results
133 134 135 136 137 138 139 140 141 |
# File 'lib/reviewer/arguments.rb', line 133 def format return :json if json? value = [:format].to_sym return value if KNOWN_FORMATS.include?(value) session_formatter.invalid_format([:format], KNOWN_FORMATS) :streaming end |
#help? ⇒ Boolean
Whether the –help flag was passed
113 |
# File 'lib/reviewer/arguments.rb', line 113 def help? = [:help] |
#json? ⇒ Boolean
Whether to output results as JSON
128 |
# File 'lib/reviewer/arguments.rb', line 128 def json? = [:json] |
#keywords ⇒ Arguments::Keywords
The leftover arguments collected from the command line without being associated with a flag
108 |
# File 'lib/reviewer/arguments.rb', line 108 def keywords = @keywords ||= Arguments::Keywords.new(.arguments) |
#raw? ⇒ Boolean
Whether to force raw/passthrough output regardless of tool count
123 |
# File 'lib/reviewer/arguments.rb', line 123 def raw? = [:raw] |
#runner_strategy(multiple_tools:) ⇒ Class
Determines the appropriate runner strategy based on CLI flags
152 153 154 155 156 157 |
# File 'lib/reviewer/arguments.rb', line 152 def runner_strategy(multiple_tools:) return Runner::Strategies::Passthrough if raw? return Runner::Strategies::Captured unless streaming? multiple_tools ? Runner::Strategies::Captured : Runner::Strategies::Passthrough end |
#streaming? ⇒ Boolean
Whether output should be streamed directly (not captured for later formatting)
146 |
# File 'lib/reviewer/arguments.rb', line 146 def streaming? = format == :streaming |
#tags ⇒ Arguments::Tags
The tag arguments collected from the command line via the -t or --tags flag
91 |
# File 'lib/reviewer/arguments.rb', line 91 def = ||= Arguments::Tags.new(provided: [:tags]) |
#to_h ⇒ Hash Also known as: inspect
Converts the arguments to a hash for versatility
79 80 81 82 83 84 85 |
# File 'lib/reviewer/arguments.rb', line 79 def to_h { files: files.raw, tags: .raw, keywords: keywords.raw } end |
#version? ⇒ Boolean
Whether the –version flag was passed
118 |
# File 'lib/reviewer/arguments.rb', line 118 def version? = [:version] |