Class: Teapot::Command::Status
- Defined in:
- lib/teapot/command/status.rb
Overview
A command to show git status of packages.
Instance Method Summary collapse
-
#process(selection) ⇒ Object
Process and display the selection.
-
#repository_for(package) ⇒ Object
Open the git repository for a package, or return nil if the package doesn’t have a repository yet.
-
#terminal(output = $stdout) ⇒ Object
Create a terminal with custom styles for colorizing git status information.
Methods inherited from Selection
Instance Method Details
#process(selection) ⇒ Object
Process and display the selection.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/teapot/command/status.rb', line 39 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
Open the git repository for a package, or return nil if the package doesn’t have a repository yet.
30 31 32 33 34 35 |
# File 'lib/teapot/command/status.rb', line 30 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
Create a terminal with custom styles for colorizing git status information.
19 20 21 22 23 24 25 |
# File 'lib/teapot/command/status.rb', line 19 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 |