Class: Fixi::Command::Sum

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.arghelpObject



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

def self.arghelp
  "<file>"
end

.detailsObject



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

def self.details
  "This command operates on files and does not require an index to exist."
end

.synopsisObject



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

def self.synopsis
  "Calculate checksum(s) of a file"
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
# File 'lib/fixi/command/sum.rb', line 18

def execute args
  opts = Trollop::options args do
    banner Fixi::Command.banner "sum"
    opt :algorithms, "Checksum algorithm(s) to use. This is a comma-separated
      list, which may include  md5, sha1, sha256, sha384, and sha512. At least
      one must be specified.".pack, :short => 'l', :type => :string,
      :required => true
  end
  unless args[0]
    raise "Must specify a file."
    exit 1
  end
  path = args[0]
  unless File.exists?(path)
    raise "No such file: #{path}"
    exit 1
  end
  hexdigests = Fixi::hexdigests(Fixi::digests(opts[:algorithms]), path)
  hexdigests.each { |hexdigest| puts "#{hexdigest}" }
end