Sha256: e010e38b3afeb5e34003cc2d96f723904ed48270b6b15c2400922047a7f72e7b

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true
require_relative '../source/source_locator'

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

      # :reek:UtilityFunction
      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

      # :reek:UtilityFunction
      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

2 entries across 2 versions & 1 rubygems

Version Path
reek-4.0.0 lib/reek/cli/input.rb
reek-4.0.0.pre1 lib/reek/cli/input.rb