class Balmora::Command::Pacman

Public Class Methods

new(state, command) click to toggle source
Calls superclass method Balmora::Command::new
# File lib/balmora/command/pacman.rb, line 3
def initialize(state, command)
  super(state, command)
  @bin = ['sudo', 'pacman']
end

Public Instance Methods

_installed() click to toggle source
# File lib/balmora/command/pacman.rb, line 59
def _installed()
  packages =
    @shell.
    run!(['pacman', '-Q'], verbose: false).
    split("\n").
    collect() { |package|
      package.split(' ')[0]
    }

  return packages
end
init() click to toggle source
Calls superclass method Balmora::Command#init
# File lib/balmora/command/pacman.rb, line 8
def init()
  super()
  @action = @variables.inject(@action)
  @packages = @variables.inject(@packages)
  @synchronize = @variables.inject(@synchronize)
end
options() click to toggle source
Calls superclass method Balmora::Command#options
# File lib/balmora/command/pacman.rb, line 15
def options()
  return super().concat([:action, :packages, :synchronize])
end
run() click to toggle source
# File lib/balmora/command/pacman.rb, line 34
def run()
  command = '-S'

  if @synchronize != false
    command += 'y'
  end

  if @action == 'install'
    packages = @packages - _installed()
  elsif @action == 'update'
    packages = @packages
  elsif @action == 'remove'
    packages = @packages & _installed()
    command = '-R'
  else
    raise Error.new("Wrong action #{@action.inspect()}")
  end

  if packages.length == 0
    return
  end

  @shell.system([*@bin, command, *packages, '--noconfirm'])
end
verify() click to toggle source
# File lib/balmora/command/pacman.rb, line 19
def verify()
  if @action.nil?()
    raise Error.new('"action" should be set')
  end

  if !['install', 'update', 'remove'].include?(@action)
    raise Error.new('wrong "action" value; allowed values: install, ' +
      'update, remove')
  end

  if @packages.nil?() || @packages.empty?()
    raise Error.new('"packages" should be set')
  end
end