Class: Fixi::Command::Add

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.arghelpObject



9
10
11
# File 'lib/fixi/command/add.rb', line 9

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

.detailsObject



13
14
15
# File 'lib/fixi/command/add.rb', line 13

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

.synopsisObject



5
6
7
# File 'lib/fixi/command/add.rb', line 5

def self.synopsis
  "Add new files to the index"
end

Instance Method Details

#execute(args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fixi/command/add.rb', line 17

def execute args
  opts = Trollop::options args do
    banner Fixi::Command.banner "add"
    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.find(path) do |abspath|
    relpath = index.relpath(abspath)
    unless index.contains?(relpath)
      puts "A #{opts[:absolute] ? abspath : relpath}"
      index.add(relpath) unless opts[:dry_run]
    end
  end

end