Class: Fixi::Command::Rm

Inherits:
Object
  • Object
show all
Defined in:
lib/fixi/command/rm.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.arghelpObject



10
11
12
# File 'lib/fixi/command/rm.rb', line 10

def self.arghelp
  "[<dir>|<file>]"
end

.detailsObject



14
15
16
# File 'lib/fixi/command/rm.rb', line 14

def self.details
  "If no argument is given, the current directory ('.') is assumed."
end

.synopsisObject



6
7
8
# File 'lib/fixi/command/rm.rb', line 6

def self.synopsis
  "Delete old files from the index"
end

Instance Method Details

#execute(args) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fixi/command/rm.rb', line 18

def execute args
  opts = Trollop::options args do
    banner Fixi::Command.banner "rm"
    opt :absolute, "Show absolute paths. By default, paths are reported
      relative to the index root.".pack
    opt :dry_run, "Don't do anything; just report what would be done"
  end
  path = File.expand_path(args[0] || ".")
  index = Fixi::Index.new(path)

  index.each(args[0]) do |hash|
    relpath = hash['relpath']
    abspath = index.rootpath + '/' + relpath
    if index.file_in_scope(relpath)
      unless File.exists?(abspath)
        puts "D #{opts[:absolute] ? abspath : relpath}"
        index.delete relpath unless opts[:dry_run]
      end
    else
      puts "X #{opts[:absolute] ? abspath : relpath}"
      index.delete relpath unless opts[:dry_run]
    end
  end

end