require 'reek/source'

module Reek
  module CLI
    #
    # CLI Input utility
    #
    module Input
      def sources
        if input_was_piped?
          source_from_pipe
        else
          if no_source_files_given?
            working_directory_as_source
          else
            sources_from_argv
          end
        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(['.']).all_sources
      end

      def sources_from_argv
        Source::SourceLocator.new(@argv).all_sources
      end

      def source_from_pipe
        [$stdin.to_reek_source('$stdin')]
      end
    end
  end
end

require 'reek/source'

module Reek
  module CLI
    #
    # CLI Input utility
    #
    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(['.']).all_sources
      end

      def sources_from_argv
        Source::SourceLocator.new(@argv).all_sources
      end

      def source_from_pipe
        [$stdin.to_reek_source('$stdin')]
      end
    end
  end
end

Fix file arguments without TTY
Fix file arguments without TTY

When using reek as part of a build process, there might not be a TTY.
This does not necessarily mean Ruby code is piped into reek via $stdin,
but reek ignores file arguments in this case. This leads to unexpected
behavior as the build script will continue to work on the terminal, but
will not scan any files on the build server.

This is fixed by only reading from $stdin when no file arguments are
given.
