class SevenZip

Constants

SUPPORTED_ARCHIVES

Public Class Methods

archive(path) click to toggle source
# File lib/cli_chef/apps/sevenzip.rb, line 80
def self.archive(path)
  SevenZip::Archive.new(path: path)
end

Public Instance Methods

extract(archive, **opts) click to toggle source
# File lib/cli_chef/apps/sevenzip.rb, line 106
def extract(archive, **opts)
  type = opts[:full_path] == false ? :extract : :extract_full_paths
  args = { type => true, file: archive, yes: true, show_progress: true }.merge(opts.except(type, :file, :yes))
  run(**args) do |line, stream, job|
    job.percent = line.extract_numbers.first if line =~ /\d+\%/
  end
end
extract!(archive, **opts) click to toggle source
# File lib/cli_chef/apps/sevenzip.rb, line 114
def extract!(archive, **opts)
  extract(archive, opts.merge(synchronous: true))
end
help() click to toggle source
# File lib/cli_chef/apps/sevenzip.rb, line 72
def help
  run!(help: true).body
end
list(archive, **opts) click to toggle source
# File lib/cli_chef/apps/sevenzip.rb, line 86
def list(archive, **opts)
  args = { list: true, archive: archive, show_technical: true }.merge(opts.except(:list, :archive, :show_technical))
  run!(args).body.split('----------', 2).last.split("\n\n").map do |details|
    hash = details.split("\n").hmap do |attribute|
      next if attribute.empty?
      key, value = attribute.split(' = ', 2)
      [key.downcase.gsub(/\s+/, '_').to_sym, value]
    end
    Archive::Item.new(hash)
  end
end
list_dirs(archive, **opts) click to toggle source
# File lib/cli_chef/apps/sevenzip.rb, line 102
def list_dirs(archive, **opts)
  list(archive, **opts).select { |i| i.is_a?(SevenZip::Archive::Dir) }
end
list_files(archive, **opts) click to toggle source
# File lib/cli_chef/apps/sevenzip.rb, line 98
def list_files(archive, **opts)
  list(archive, **opts).select { |i| i.is_a?(SevenZip::Archive::File) }
end
test(archive, **opts) click to toggle source

TODO Have test return something better

# File lib/cli_chef/apps/sevenzip.rb, line 130
def test(archive, **opts)
  args = { test: true, file: archive, yes: nil }.merge(opts.except(:test, :file, :yes))
  run(**args)
end
test!(archive, **opts) click to toggle source
# File lib/cli_chef/apps/sevenzip.rb, line 135
def test!(archive, **opts)
  test(archive, opts.merge(synchronous: true))
end
version() click to toggle source
# File lib/cli_chef/apps/sevenzip.rb, line 76
def version
  help.scan(/(?<=7-zip )\d+\.\d+\s?\w*/i).first
end