Sha256: 35cd133afd83d3d51d72cb75ab086d754d0b965cabb4981dcd38a7ca39f651e9

Contents?: true

Size: 967 Bytes

Versions: 3

Compression:

Stored size: 967 Bytes

Contents

require_relative '../source/source_locator'

module Reek
  module CLI
    #
    # CLI Input utility
    #
    # @api private
    module Input
      def sources
        if no_source_files_given?
          if input_was_piped?
            source_from_pipe
          else
            working_directory_as_source
          end
        else
          sources_from_argv
        end
      end

      private

      def input_was_piped?
        !$stdin.tty?
      end

      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

      def working_directory_as_source
        Source::SourceLocator.new(['.']).sources
      end

      def sources_from_argv
        Source::SourceLocator.new(argv).sources
      end

      def source_from_pipe
        [$stdin]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reek-3.3.1 lib/reek/cli/input.rb
reek-3.3.0 lib/reek/cli/input.rb
reek-3.2 lib/reek/cli/input.rb