Sha256: e2efa7bd4d9d0878fef82f256efc79acbf9ee3c639d2d4fb12ea737b7fde51c3

Contents?: true

Size: 971 Bytes

Versions: 7

Compression:

Stored size: 971 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

7 entries across 7 versions & 1 rubygems

Version Path
reek-3.2.1 lib/reek/cli/input.rb
reek-3.1 lib/reek/cli/input.rb
reek-3.0.4 lib/reek/cli/input.rb
reek-3.0.3 lib/reek/cli/input.rb
reek-3.0.2 lib/reek/cli/input.rb
reek-3.0.1 lib/reek/cli/input.rb
reek-3.0.0 lib/reek/cli/input.rb