Class: Intent::Projects::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/intent/verbs/status.rb

Class Method Summary collapse

Class Method Details

.run(projects_dir) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/intent/verbs/status.rb', line 4

def self.run(projects_dir)
  project_index = {}

  Dir["#{projects_dir}/*"].each do |project|
    if Dir.exists?(project) && Dir.exists?("#{project}/.git")
      Dir.chdir(project)
      git_output = `git status`
      project_name = Pathname.new(project).basename

      status = {
        untracked_files: git_output.include?('Untracked files'),
        unstaged_edits: git_output.include?('Changes not staged for commit')
      }

      if status[:untracked_files] || status[:unstaged_edits]
        project_index[project_name] = status
      end
    end
  end

  pastel = Pastel.new

  project_index.each do |key, value|
    result = []
    if value[:untracked_files]
      result << pastel.red('untracked files')
    end
    if value[:unstaged_edits]
      result << pastel.red('unstaged edits')
    end
    puts "#{pastel.bold('+')}#{pastel.bold(key)} contains #{result.join(' and ')}."
  end
end