Class: Balmora::Command::Pacman
Direct Known Subclasses
Yaourt
Instance Method Summary
collapse
#_execute, #execute, #option
Constructor Details
#initialize(state, command) ⇒ Pacman
Returns a new instance of Pacman.
3
4
5
6
|
# File 'lib/balmora/command/pacman.rb', line 3
def initialize(state, command)
super(state, command)
@bin = ['sudo', 'pacman']
end
|
Instance Method Details
#_installed ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
|
# 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 ⇒ Object
8
9
10
11
12
13
|
# 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 ⇒ Object
15
16
17
|
# File 'lib/balmora/command/pacman.rb', line 15
def options()
return super().concat([:action, :packages, :synchronize])
end
|
#run ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# 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 ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# 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
|