class Reek::CLI::Application
Represents an instance of a Reek
application. This is the entry point for all invocations of Reek
from the command line.
Attributes
Public Class Methods
Source
# File lib/reek/cli/application.rb, line 22 def initialize(argv) @options = configure_options(argv) @configuration = configure_app_configuration(options.config_file) @command = command_class.new(options: options, sources: sources, configuration: configuration) end
Public Instance Methods
Source
# File lib/reek/cli/application.rb, line 30 def execute show_configuration_path command.execute end
Private Instance Methods
Source
# File lib/reek/cli/application.rb, line 76 def command_class options.generate_todo_list ? Command::TodoListCommand : Command::ReportCommand end
Source
# File lib/reek/cli/application.rb, line 46 def configure_app_configuration(config_file) Configuration::AppConfiguration.from_path(config_file) rescue Errors::ConfigFileError => error warn "Error: #{error}" exit Status::DEFAULT_ERROR_EXIT_CODE end
Source
# File lib/reek/cli/application.rb, line 39 def configure_options(argv) Options.new(argv).parse rescue OptionParser::InvalidOption => error warn "Error: #{error}" exit Status::DEFAULT_ERROR_EXIT_CODE end
Source
# File lib/reek/cli/application.rb, line 120 def disable_progress_output_unless_verbose options.progress_format = :quiet unless options.show_empty end
Source
# File lib/reek/cli/application.rb, line 98 def input_was_piped? !$stdin.tty? end
@quality :reek:UtilityFunction
Source
# File lib/reek/cli/application.rb, line 102 def no_source_files_given? # At this point we have deleted all options from argv. The only remaining entries # are paths to the source files. If argv is empty, this means that no files were given. argv.empty? end
Source
# File lib/reek/cli/application.rb, line 72 def path_relative_to_working_directory(path) Pathname(path).realpath.relative_path_from(Pathname.pwd) end
Returns the path that is relative to the current working directory given an absolute path. E.g. if the given absolute path is “/foo/bar/baz/.reek.yml” and your working directory is “/foo/bar” this method would return “baz/.reek.yml”
@param path [String] Absolute path @return [Pathname], e.g. ‘config/.reek.yml’
:reek: UtilityFunction
Source
# File lib/reek/cli/application.rb, line 53 def show_configuration_path return unless options.show_configuration_path path = Configuration::ConfigurationFileFinder.find(path: options.config_file) if path puts "Using '#{path_relative_to_working_directory(path)}' as configuration file." else puts 'Not using any configuration file.' end end
Source
# File lib/reek/cli/application.rb, line 116 def source_from_pipe [Source::SourceCode.from($stdin, origin: options.stdin_filename)] end
Source
# File lib/reek/cli/application.rb, line 80 def sources if no_source_files_given? if input_was_piped? disable_progress_output_unless_verbose source_from_pipe else working_directory_as_source end else sources_from_argv end end
Source
# File lib/reek/cli/application.rb, line 112 def sources_from_argv Source::SourceLocator.new(argv, configuration: configuration, options: options).sources end
Source
# File lib/reek/cli/application.rb, line 108 def working_directory_as_source Source::SourceLocator.new(['.'], configuration: configuration, options: options).sources end