Class: Cir::Cli::StatusCommand

Inherits:
CommandWithRepository show all
Defined in:
lib/cir/cli/status_command.rb

Overview

Status command

Instance Attribute Summary

Attributes inherited from CommandWithRepository

#repository

Attributes inherited from Command

#args, #files, #global_args

Instance Method Summary collapse

Methods inherited from CommandWithRepository

#initialize

Methods inherited from Command

#initialize

Constructor Details

This class inherits a constructor from Cir::Cli::CommandWithRepository

Instance Method Details

#optsObject



20
21
22
23
24
25
26
# File 'lib/cir/cli/status_command.rb', line 20

def opts
  Trollop::Parser.new do
    banner "Show status of registered files."
    opt :show_diff, "Show diffs for changed files", :default => false
    opt :all, "Display all files even those that haven't been changed", :default => false
  end
end

#processObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cir/cli/status_command.rb', line 28

def process
  files = self.repository.status(self.files.empty? ? nil : self.files)

  files.each do |file|
    diff = file.diff
    if diff.changed?
      puts "File #{file.file_path} changed."
      puts "#{diff.to_s}\n" if self.args[:show_diff]
    elsif self.args[:all]
      puts "File #{file.file_path} is the same."
    end
  end
end