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/options.rb,
lib/reviewer/arguments/keywords.rb
Overview
Handles option parsing for rvw and fmt commands
Defined Under Namespace
Modules: Options 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
-
#capabilities? ⇒ Boolean
Whether the --capabilities flag was passed.
-
#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.
-
#invalid_files_option? ⇒ Boolean
Whether a files option was supplied without a usable value.
-
#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.
43 44 45 46 47 48 49 50 |
# File 'lib/reviewer/arguments.rb', line 43 def initialize( = ARGV, output: Output.new) @output = output = .to_a.dup @invalid_files_option = false @parser = Slop::Options.new Options.configure(@parser, files_callback: files_validation_callback) = @parser.parse() end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
28 29 30 |
# File 'lib/reviewer/arguments.rb', line 28 def end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
30 31 32 |
# File 'lib/reviewer/arguments.rb', line 30 def output @output end |
Instance Method Details
#capabilities? ⇒ Boolean
Whether the --capabilities flag was passed
115 |
# File 'lib/reviewer/arguments.rb', line 115 def capabilities? = [:capabilities] |
#files ⇒ Arguments::Files
The file arguments collected from the command line via the -f or --files flag
78 79 80 81 82 83 84 85 |
# File 'lib/reviewer/arguments.rb', line 78 def files @files ||= Arguments::Files.new( provided: [:files], keywords: keywords.for_files, output: output, on_git_error: session_formatter.method(:git_error) ) end |
#format ⇒ Symbol
The output format for results
125 126 127 128 129 130 131 132 133 |
# File 'lib/reviewer/arguments.rb', line 125 def format return :json if json? value = [:format].to_sym return value if KNOWN_FORMATS.include?(value) session_formatter.invalid_format([:format], KNOWN_FORMATS) unless invalid_files_option? :streaming end |
#help? ⇒ Boolean
Whether the --help flag was passed
95 |
# File 'lib/reviewer/arguments.rb', line 95 def help? = [:help] |
#invalid_files_option? ⇒ Boolean
Whether a files option was supplied without a usable value
120 |
# File 'lib/reviewer/arguments.rb', line 120 def invalid_files_option? = @invalid_files_option |
#json? ⇒ Boolean
Whether to output results as JSON
110 |
# File 'lib/reviewer/arguments.rb', line 110 def json? = [:json] |
#keywords ⇒ Arguments::Keywords
The leftover arguments collected from the command line without being associated with a flag
90 |
# File 'lib/reviewer/arguments.rb', line 90 def keywords = @keywords ||= Arguments::Keywords.new(.arguments) |
#raw? ⇒ Boolean
Whether to force raw/passthrough output regardless of tool count
105 |
# File 'lib/reviewer/arguments.rb', line 105 def raw? = [:raw] |
#runner_strategy(multiple_tools:) ⇒ Class
Determines the appropriate runner strategy based on CLI flags
144 145 146 147 148 149 |
# File 'lib/reviewer/arguments.rb', line 144 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)
138 |
# File 'lib/reviewer/arguments.rb', line 138 def streaming? = format == :streaming |
#tags ⇒ Arguments::Tags
The tag arguments collected from the command line via the -t or --tags flag
73 |
# File 'lib/reviewer/arguments.rb', line 73 def = ||= Arguments::Tags.new(provided: [:tags]) |
#to_h ⇒ Hash Also known as: inspect
Converts the arguments to a hash for versatility
61 62 63 64 65 66 67 |
# File 'lib/reviewer/arguments.rb', line 61 def to_h { files: files.raw, tags: .raw, keywords: keywords.raw } end |
#version? ⇒ Boolean
Whether the --version flag was passed
100 |
# File 'lib/reviewer/arguments.rb', line 100 def version? = [:version] |