Class: Reek::CLI::Options
- Inherits:
-
Object
- Object
- Reek::CLI::Options
- Defined in:
- lib/reek/cli/options.rb
Overview
Parses the command line
See Command-Line-Options for details.
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
-
#colored ⇒ Object
Returns the value of attribute colored.
-
#config_file ⇒ Object
Returns the value of attribute config_file.
-
#failure_exit_code ⇒ Object
Returns the value of attribute failure_exit_code.
-
#force_exclusion ⇒ Object
Returns the value of attribute force_exclusion.
-
#generate_todo_list ⇒ Object
Returns the value of attribute generate_todo_list.
-
#location_format ⇒ Object
Returns the value of attribute location_format.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
-
#progress_format ⇒ Object
Returns the value of attribute progress_format.
-
#report_format ⇒ Object
Returns the value of attribute report_format.
-
#show_configuration_path ⇒ Object
Returns the value of attribute show_configuration_path.
-
#show_empty ⇒ Object
Returns the value of attribute show_empty.
-
#show_links ⇒ Object
Returns the value of attribute show_links.
-
#smells_to_detect ⇒ Object
readonly
Returns the value of attribute smells_to_detect.
-
#sorting ⇒ Object
Returns the value of attribute sorting.
-
#stdin_filename ⇒ Object
Returns the value of attribute stdin_filename.
-
#success_exit_code ⇒ Object
Returns the value of attribute success_exit_code.
Instance Method Summary collapse
- #force_exclusion? ⇒ Boolean
-
#initialize(argv = []) ⇒ Options
constructor
A new instance of Options.
- #parse ⇒ Object
- #set_alternative_formatter_options ⇒ Object private
- #set_banner ⇒ Object private
- #set_configuration_options ⇒ Object private
- #set_exit_codes ⇒ Object private
- #set_generate_todo_list_options ⇒ Object private
- #set_report_formatting_options ⇒ Object private
- #set_up_color_option ⇒ Object private
- #set_up_force_exclusion_option ⇒ Object private
- #set_up_location_formatting_options ⇒ Object private
- #set_up_parser ⇒ Object private
- #set_up_progress_formatting_options ⇒ Object private
- #set_up_sorting_option ⇒ Object private
- #set_up_verbosity_options ⇒ Object private
- #set_utility_options ⇒ Object private
-
#tty_output? ⇒ Boolean
private
TTY output generally means the output will not undergo further processing by a machine, but will be viewed by a human.
Constructor Details
#initialize(argv = []) ⇒ Options
Returns a new instance of Options.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/reek/cli/options.rb', line 38 def initialize(argv = []) @argv = argv @parser = OptionParser.new @report_format = :text @location_format = :numbers @progress_format = tty_output? ? :dots : :quiet @show_links = true @smells_to_detect = [] @colored = tty_output? @success_exit_code = Status::DEFAULT_SUCCESS_EXIT_CODE @failure_exit_code = Status::DEFAULT_FAILURE_EXIT_CODE @generate_todo_list = false @force_exclusion = false @show_configuration_path = false set_up_parser end |
Instance Attribute Details
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
22 23 24 |
# File 'lib/reek/cli/options.rb', line 22 def argv @argv end |
#colored ⇒ Object
Returns the value of attribute colored.
23 24 25 |
# File 'lib/reek/cli/options.rb', line 23 def colored @colored end |
#config_file ⇒ Object
Returns the value of attribute config_file.
23 24 25 |
# File 'lib/reek/cli/options.rb', line 23 def config_file @config_file end |
#failure_exit_code ⇒ Object
Returns the value of attribute failure_exit_code.
23 24 25 |
# File 'lib/reek/cli/options.rb', line 23 def failure_exit_code @failure_exit_code end |
#force_exclusion ⇒ Object
Returns the value of attribute force_exclusion.
23 24 25 |
# File 'lib/reek/cli/options.rb', line 23 def force_exclusion @force_exclusion end |
#generate_todo_list ⇒ Object
Returns the value of attribute generate_todo_list.
23 24 25 |
# File 'lib/reek/cli/options.rb', line 23 def generate_todo_list @generate_todo_list end |
#location_format ⇒ Object
Returns the value of attribute location_format.
23 24 25 |
# File 'lib/reek/cli/options.rb', line 23 def location_format @location_format end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
22 23 24 |
# File 'lib/reek/cli/options.rb', line 22 def parser @parser end |
#progress_format ⇒ Object
Returns the value of attribute progress_format.
23 24 25 |
# File 'lib/reek/cli/options.rb', line 23 def progress_format @progress_format end |
#report_format ⇒ Object
Returns the value of attribute report_format.
23 24 25 |
# File 'lib/reek/cli/options.rb', line 23 def report_format @report_format end |
#show_configuration_path ⇒ Object
Returns the value of attribute show_configuration_path.
23 24 25 |
# File 'lib/reek/cli/options.rb', line 23 def show_configuration_path @show_configuration_path end |
#show_empty ⇒ Object
Returns the value of attribute show_empty.
23 24 25 |
# File 'lib/reek/cli/options.rb', line 23 def show_empty @show_empty end |
#show_links ⇒ Object
Returns the value of attribute show_links.
23 24 25 |
# File 'lib/reek/cli/options.rb', line 23 def show_links @show_links end |
#smells_to_detect ⇒ Object (readonly)
Returns the value of attribute smells_to_detect.
22 23 24 |
# File 'lib/reek/cli/options.rb', line 22 def smells_to_detect @smells_to_detect end |
#sorting ⇒ Object
Returns the value of attribute sorting.
23 24 25 |
# File 'lib/reek/cli/options.rb', line 23 def sorting @sorting end |
#stdin_filename ⇒ Object
Returns the value of attribute stdin_filename.
23 24 25 |
# File 'lib/reek/cli/options.rb', line 23 def stdin_filename @stdin_filename end |
#success_exit_code ⇒ Object
Returns the value of attribute success_exit_code.
23 24 25 |
# File 'lib/reek/cli/options.rb', line 23 def success_exit_code @success_exit_code end |
Instance Method Details
#force_exclusion? ⇒ Boolean
62 63 64 |
# File 'lib/reek/cli/options.rb', line 62 def force_exclusion? @force_exclusion end |
#parse ⇒ Object
56 57 58 59 60 |
# File 'lib/reek/cli/options.rb', line 56 def parse parser.parse!(argv) Rainbow.enabled = colored self end |
#set_alternative_formatter_options ⇒ Object (private)
131 132 133 134 135 136 137 138 139 |
# File 'lib/reek/cli/options.rb', line 131 def parser.separator "\nReport format:" parser.on( '-f', '--format FORMAT', [:html, :text, :yaml, :json, :xml, :github], 'Report smells in the given format:', ' html', ' text (default)', ' yaml', ' json', ' xml', ' github') do |opt| self.report_format = opt end end |
#set_banner ⇒ Object (private)
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/reek/cli/options.rb', line 88 def program_name = parser.program_name parser. = <<-BANNER.gsub(/^ +/, '') Usage: #{program_name} [options] [files] Examples: #{program_name} lib/*.rb #{program_name} -s lib cat my_class.rb | #{program_name} See https://github.com/troessner/reek for detailed help. BANNER end |
#set_configuration_options ⇒ Object (private)
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/reek/cli/options.rb', line 105 def parser.separator 'Configuration:' parser.on('-c', '--config FILE', 'Read configuration options from FILE') do |file| self.config_file = Pathname.new(file) end parser.on('--smell SMELL', 'Only look for a specific smell.', 'Call it like this: reek --smell MissingSafeMethod source.rb', "Check out #{DocumentationLink.build('Code Smells')} " \ 'for a list of smells') do |smell| smells_to_detect << smell end parser.on('--stdin-filename FILE', 'When passing code in via pipe, assume this filename when ' \ 'checking file or directory rules in the config.') do |file| self.stdin_filename = file end end |
#set_exit_codes ⇒ Object (private)
210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/reek/cli/options.rb', line 210 def set_exit_codes parser.separator "\nExit codes:" parser.on('--success-exit-code CODE', 'The exit code when no smells are found ' \ "(default: #{Status::DEFAULT_SUCCESS_EXIT_CODE})") do |option| self.success_exit_code = Integer(option) end parser.on('--failure-exit-code CODE', 'The exit code when smells are found ' \ "(default: #{Status::DEFAULT_FAILURE_EXIT_CODE})") do |option| self.failure_exit_code = Integer(option) end end |
#set_generate_todo_list_options ⇒ Object (private)
124 125 126 127 128 129 |
# File 'lib/reek/cli/options.rb', line 124 def parser.separator "\nGenerate a todo list:" parser.on('-t', '--todo', 'Generate a todo list') do self.generate_todo_list = true end end |
#set_report_formatting_options ⇒ Object (private)
142 143 144 145 146 147 148 149 150 |
# File 'lib/reek/cli/options.rb', line 142 def parser.separator "\nText format options:" set_up_color_option set_up_sorting_option set_up_force_exclusion_option end |
#set_up_color_option ⇒ Object (private)
152 153 154 155 156 |
# File 'lib/reek/cli/options.rb', line 152 def set_up_color_option parser.on('--[no-]color', 'Use colors for the output (default: true)') do |opt| self.colored = opt end end |
#set_up_force_exclusion_option ⇒ Object (private)
201 202 203 204 205 206 207 |
# File 'lib/reek/cli/options.rb', line 201 def set_up_force_exclusion_option parser.on('--force-exclusion', 'Force excluding files specified in the configuration `exclude_paths`', ' even if they are explicitly passed as arguments') do |force_exclusion| self.force_exclusion = force_exclusion end end |
#set_up_location_formatting_options ⇒ Object (private)
174 175 176 177 178 179 180 181 182 183 |
# File 'lib/reek/cli/options.rb', line 174 def parser.on('-n', '--[no-]line-numbers', 'Show line numbers in the output (default: true)') do |show_numbers| self.location_format = show_numbers ? :numbers : :plain end parser.on('-s', '--single-line', 'Show location in editor-compatible single-line-per-smell format') do self.location_format = :single_line end end |
#set_up_parser ⇒ Object (private)
78 79 80 81 82 83 84 85 86 |
# File 'lib/reek/cli/options.rb', line 78 def set_up_parser set_exit_codes end |
#set_up_progress_formatting_options ⇒ Object (private)
185 186 187 188 189 190 |
# File 'lib/reek/cli/options.rb', line 185 def parser.on('-P', '--[no-]progress', 'Show progress of each source as it is examined (default: true)') do |show_progress| self.progress_format = show_progress ? :dots : :quiet end end |
#set_up_sorting_option ⇒ Object (private)
192 193 194 195 196 197 198 199 |
# File 'lib/reek/cli/options.rb', line 192 def set_up_sorting_option parser.on('--sort-by SORTING', [:smelliness, :none], 'Sort reported files by the given criterium:', ' smelliness ("smelliest" files first)', ' none (default - output in processing order)') do |sorting| self.sorting = sorting end end |
#set_up_verbosity_options ⇒ Object (private)
159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/reek/cli/options.rb', line 159 def parser.on('-V', '--[no-]empty-headings', 'Show headings for smell-free source files (default: false)') do |show_empty| self.show_empty = show_empty end parser.on('-U', '--[no-]documentation', 'Show link to related documentation page for each smell (default: true)') do |show_links| self.show_links = show_links end parser.on(nil, '--[no-]show-configuration-path', 'Show which configuration file Reek is using (default: false)') do |show_configuration_path| self.show_configuration_path = show_configuration_path end end |
#set_utility_options ⇒ Object (private)
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/reek/cli/options.rb', line 225 def parser.separator "\nUtility options:" parser.on_tail('-h', '--help', 'Show this message') do puts parser exit end parser.on_tail('-l', '--list', 'List all available smell detectors') do puts "All available smell detectors:\n\n" puts DetectorRepository.available_detector_names puts "\nCheck out #{DocumentationLink.build('Code Smells')} " \ 'for a details on each detector' exit end parser.on_tail('-v', '--version', 'Show version') do puts "#{parser.program_name} #{Reek::Version::STRING}\n" exit end end |
#tty_output? ⇒ Boolean (private)
TTY output generally means the output will not undergo further processing by a machine, but will be viewed by a human. This means features like coloring can be safely enabled by default.
73 74 75 |
# File 'lib/reek/cli/options.rb', line 73 def tty_output? $stdout.tty? end |