Class: Teapot::Command::Status

Inherits:
Selection
  • Object
show all
Defined in:
lib/teapot/command/status.rb

Instance Method Summary collapse

Methods inherited from Selection

#call, #selection, #targets

Instance Method Details

#process(selection) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/teapot/command/status.rb', line 45

def process(selection)
	context = selection.context
	terminal = self.terminal
	
	selection.resolved.each do |package|
		if repository = repository_for(package)
			changes = {}
			repository.status do |file, status|
				unless status == [:ignored]
					changes[file] = status
				end
			end
			
			next if changes.empty?
			
			terminal.puts "Package #{package.name} (from #{package.path}):"
			
			changes.each do |file, statuses|
				terminal.puts "\t#{file} (#{statuses})", style: statuses.last
			end
		end
	end
end

#repository_for(package) ⇒ Object



38
39
40
41
42
43
# File 'lib/teapot/command/status.rb', line 38

def repository_for(package)
	Rugged::Repository.new(package.path.to_s)
rescue Rugged::RepositoryError
	# In some cases, a repository might not exist yet, so just skip the package.
	nil
end

#terminal(output = $stdout) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/teapot/command/status.rb', line 30

def terminal(output = $stdout)
	Console::Terminal.for(output).tap do |terminal|
		terminal[:worktree_new] = terminal.style(:green)
		terminal[:worktree_modified] = terminal.style(:yellow)
		terminal[:worktree_deleted] = terminal.style(:red)
	end
end