Class: Reek::CLI::Application
- Inherits:
-
Object
- Object
- Reek::CLI::Application
- Defined in:
- lib/reek/cli/application.rb
Overview
Represents an instance of a Reek application. This is the entry point for all invocations of Reek from the command line.
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
private
Returns the value of attribute command.
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#options ⇒ Object
readonly
private
Returns the value of attribute options.
Instance Method Summary collapse
- #argv ⇒ Object private
- #command_class ⇒ Object private
- #configure_app_configuration(config_file) ⇒ Object private
- #configure_options(argv) ⇒ Object private
- #disable_progress_output_unless_verbose ⇒ Object private
- #execute ⇒ Object
-
#initialize(argv) ⇒ Application
constructor
A new instance of Application.
- #input_was_piped? ⇒ Boolean private
- #no_source_files_given? ⇒ Boolean private
-
#path_relative_to_working_directory(path) ⇒ Pathname
private
Returns the path that is relative to the current working directory given an absolute path.
- #show_configuration_path ⇒ Object private
- #source_from_pipe ⇒ Object private
- #sources ⇒ Object private
- #sources_from_argv ⇒ Object private
- #working_directory_as_source ⇒ Object private
Constructor Details
#initialize(argv) ⇒ Application
Returns a new instance of Application.
22 23 24 25 26 27 28 |
# File 'lib/reek/cli/application.rb', line 22 def initialize(argv) @options = (argv) @configuration = configure_app_configuration(.config_file) @command = command_class.new(options: , sources: sources, configuration: configuration) end |
Instance Attribute Details
#command ⇒ Object (readonly, private)
Returns the value of attribute command.
37 38 39 |
# File 'lib/reek/cli/application.rb', line 37 def command @command end |
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
20 21 22 |
# File 'lib/reek/cli/application.rb', line 20 def configuration @configuration end |
#options ⇒ Object (readonly, private)
Returns the value of attribute options.
37 38 39 |
# File 'lib/reek/cli/application.rb', line 37 def @options end |
Instance Method Details
#argv ⇒ Object (private)
93 94 95 |
# File 'lib/reek/cli/application.rb', line 93 def argv .argv end |
#command_class ⇒ Object (private)
76 77 78 |
# File 'lib/reek/cli/application.rb', line 76 def command_class .generate_todo_list ? Command::TodoListCommand : Command::ReportCommand end |
#configure_app_configuration(config_file) ⇒ Object (private)
46 47 48 49 50 51 |
# 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 |
#configure_options(argv) ⇒ Object (private)
39 40 41 42 43 44 |
# File 'lib/reek/cli/application.rb', line 39 def (argv) Options.new(argv).parse rescue OptionParser::InvalidOption => error warn "Error: #{error}" exit Status::DEFAULT_ERROR_EXIT_CODE end |
#disable_progress_output_unless_verbose ⇒ Object (private)
120 121 122 |
# File 'lib/reek/cli/application.rb', line 120 def disable_progress_output_unless_verbose .progress_format = :quiet unless .show_empty end |
#execute ⇒ Object
30 31 32 33 |
# File 'lib/reek/cli/application.rb', line 30 def execute show_configuration_path command.execute end |
#input_was_piped? ⇒ Boolean (private)
98 99 100 |
# File 'lib/reek/cli/application.rb', line 98 def input_was_piped? !$stdin.tty? end |
#no_source_files_given? ⇒ Boolean (private)
102 103 104 105 106 |
# 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 |
#path_relative_to_working_directory(path) ⇒ Pathname (private)
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”
:reek:UtilityFunction
72 73 74 |
# File 'lib/reek/cli/application.rb', line 72 def path_relative_to_working_directory(path) Pathname(path).realpath.relative_path_from(Pathname.pwd) end |
#show_configuration_path ⇒ Object (private)
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/reek/cli/application.rb', line 53 def show_configuration_path return unless .show_configuration_path path = Configuration::ConfigurationFileFinder.find(path: .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_from_pipe ⇒ Object (private)
116 117 118 |
# File 'lib/reek/cli/application.rb', line 116 def source_from_pipe [Source::SourceCode.from($stdin, origin: .stdin_filename)] end |
#sources ⇒ Object (private)
80 81 82 83 84 85 86 87 88 89 90 91 |
# 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 |
#sources_from_argv ⇒ Object (private)
112 113 114 |
# File 'lib/reek/cli/application.rb', line 112 def sources_from_argv Source::SourceLocator.new(argv, configuration: configuration, options: ).sources end |
#working_directory_as_source ⇒ Object (private)
108 109 110 |
# File 'lib/reek/cli/application.rb', line 108 def working_directory_as_source Source::SourceLocator.new(['.'], configuration: configuration, options: ).sources end |