Skip to content

Commit aab75a2

Browse files
committed
pacman: switch to long options for more readability
I think the long command options makes it a bit easier to understand what's actually happening. ``` usage: pacman <operation> [...] operations: pacman {-h --help} pacman {-V --version} pacman {-D --database} <options> <package(s)> pacman {-F --files} [options] [file(s)] pacman {-Q --query} [options] [package(s)] pacman {-R --remove} [options] <package(s)> pacman {-S --sync} [options] [package(s)] pacman {-T --deptest} [options] [package(s)] pacman {-U --upgrade} [options] <file(s)> use 'pacman {-h --help}' with an operation for available options ``` ``` usage: pacman {-Q --query} [options] [package(s)] options: -b, --dbpath <path> set an alternate database location -c, --changelog view the changelog of a package -d, --deps list packages installed as dependencies [filter] -e, --explicit list packages explicitly installed [filter] -g, --groups view all members of a package group -i, --info view package information (-ii for backup files) -k, --check check that package files exist (-kk for file properties) -l, --list list the files owned by the queried package -m, --foreign list installed packages not found in sync db(s) [filter] -n, --native list installed packages only found in sync db(s) [filter] -o, --owns <file> query the package that owns <file> -p, --file <package> query a package file instead of the database -q, --quiet show less information for query and search -r, --root <path> set an alternate installation root -s, --search <regex> search locally-installed packages for matching strings -t, --unrequired list packages not (optionally) required by any package (-tt to ignore optdepends) [filter] -u, --upgrades list outdated packages [filter] -v, --verbose be verbose --arch <arch> set an alternate architecture --cachedir <dir> set an alternate package cache location --color <when> colorize the output --config <path> set an alternate configuration file --confirm always ask for confirmation --debug display debug messages --disable-download-timeout use relaxed timeouts for download --gpgdir <path> set an alternate home directory for GnuPG --hookdir <dir> set an alternate hook location --logfile <path> set an alternate log file --noconfirm do not ask for any confirmation --sysroot operate on a mounted guest system (root-only) ``` ``` usage: pacman {-S --sync} [options] [package(s)] options: -b, --dbpath <path> set an alternate database location -c, --clean remove old packages from cache directory (-cc for all) -d, --nodeps skip dependency version checks (-dd to skip all checks) -g, --groups view all members of a package group (-gg to view all groups and members) -i, --info view package information (-ii for extended information) -l, --list <repo> view a list of packages in a repo -p, --print print the targets instead of performing the operation -q, --quiet show less information for query and search -r, --root <path> set an alternate installation root -s, --search <regex> search remote repositories for matching strings -u, --sysupgrade upgrade installed packages (-uu enables downgrades) -v, --verbose be verbose -w, --downloadonly download packages but do not install/upgrade anything -y, --refresh download fresh package databases from the server (-yy to force a refresh even if up to date) --arch <arch> set an alternate architecture --asdeps install packages as non-explicitly installed --asexplicit install packages as explicitly installed --assume-installed <package=version> add a virtual package to satisfy dependencies --cachedir <dir> set an alternate package cache location --color <when> colorize the output --config <path> set an alternate configuration file --confirm always ask for confirmation --dbonly only modify database entries, not package files --debug display debug messages --disable-download-timeout use relaxed timeouts for download --gpgdir <path> set an alternate home directory for GnuPG --hookdir <dir> set an alternate hook location --ignore <pkg> ignore a package upgrade (can be used more than once) --ignoregroup <grp> ignore a group upgrade (can be used more than once) --logfile <path> set an alternate log file --needed do not reinstall up to date packages --noconfirm do not ask for any confirmation --noprogressbar do not show a progress bar when downloading files --noscriptlet do not execute the install scriptlet if one exists --overwrite <glob> overwrite conflicting files (can be used more than once) --print-format <string> specify how the targets should be printed --sysroot operate on a mounted guest system (root-only) ``` ``` usage: pacman {-R --remove} [options] <package(s)> options: -b, --dbpath <path> set an alternate database location -c, --cascade remove packages and all packages that depend on them -d, --nodeps skip dependency version checks (-dd to skip all checks) -n, --nosave remove configuration files -p, --print print the targets instead of performing the operation -r, --root <path> set an alternate installation root -s, --recursive remove unnecessary dependencies (-ss includes explicitly installed dependencies) -u, --unneeded remove unneeded packages -v, --verbose be verbose --arch <arch> set an alternate architecture --assume-installed <package=version> add a virtual package to satisfy dependencies --cachedir <dir> set an alternate package cache location --color <when> colorize the output --config <path> set an alternate configuration file --confirm always ask for confirmation --dbonly only modify database entries, not package files --debug display debug messages --disable-download-timeout use relaxed timeouts for download --gpgdir <path> set an alternate home directory for GnuPG --hookdir <dir> set an alternate hook location --logfile <path> set an alternate log file --noconfirm do not ask for any confirmation --noprogressbar do not show a progress bar when downloading files --noscriptlet do not execute the install scriptlet if one exists --print-format <string> specify how the targets should be printed --sysroot operate on a mounted guest system (root-only) ```
1 parent 7da526d commit aab75a2

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

lib/puppet/provider/package/pacman.rb

+9-9
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def self.yaourt?
2929

3030
# Checks if a given name is a group
3131
def self.group?(name)
32-
!pacman("-Sg", name).empty?
32+
!pacman('--sync', '--groups', name).empty?
3333
rescue Puppet::ExecutionFailure
3434
# pacman returns an expected non-zero exit code when the name is not a group
3535
false
@@ -74,7 +74,7 @@ def self.instances
7474
# returns a hash package => version of installed packages
7575
def self.get_installed_packages
7676
packages = {}
77-
execpipe([command(:pacman), "-Q"]) do |pipe|
77+
execpipe([command(:pacman), "--query"]) do |pipe|
7878
# pacman -Q output is 'packagename version-rel'
7979
regex = /^(\S+)\s(\S+)/
8080
pipe.each_line do |line|
@@ -96,7 +96,7 @@ def self.get_installed_groups(installed_packages, filter = nil)
9696
groups = {}
9797
begin
9898
# Build a hash of group name => list of packages
99-
command = [command(:pacman), "-Sgg"]
99+
command = [command(:pacman), '--sync', '-gg']
100100
command << filter if filter
101101
execpipe(command) do |pipe|
102102
pipe.each_line do |line|
@@ -134,14 +134,14 @@ def latest
134134
resource_name = @resource[:name]
135135

136136
# If target is a group, construct the group version
137-
return pacman("-Sp", "--print-format", "%n %v", resource_name).lines.map(&:chomp).sort.join(', ') if self.class.group?(resource_name)
137+
return pacman("--sync", "--print", "--print-format", "%n %v", resource_name).lines.map(&:chomp).sort.join(', ') if self.class.group?(resource_name)
138138

139139
# Start by querying with pacman first
140140
# If that fails, retry using yaourt against the AUR
141141
pacman_check = true
142142
begin
143143
if pacman_check
144-
output = pacman "-Sp", "--print-format", "%v", resource_name
144+
output = pacman "--sync", "--print", "--print-format", "%v", resource_name
145145
output.chomp
146146
else
147147
output = yaourt "-Qma", resource_name
@@ -210,8 +210,8 @@ def remove_package(purge_configs = false)
210210

211211
cmd = %w[--noconfirm --noprogressbar]
212212
cmd += uninstall_options if @resource[:uninstall_options]
213-
cmd << "-R"
214-
cmd << '-s' if is_group
213+
cmd << "--remove"
214+
cmd << '--recursive' if is_group
215215
cmd << '--nosave' if purge_configs
216216
cmd << resource_name
217217

@@ -248,7 +248,7 @@ def install_from_file
248248
else
249249
fail _("Source %{source} is not supported by pacman") % { source: source }
250250
end
251-
pacman "--noconfirm", "--noprogressbar", "-U", source
251+
pacman "--noconfirm", "--noprogressbar", "--update", source
252252
end
253253

254254
def install_from_repo
@@ -259,7 +259,7 @@ def install_from_repo
259259

260260
cmd = %w[--noconfirm --needed --noprogressbar]
261261
cmd += install_options if @resource[:install_options]
262-
cmd << "-S" << resource_name
262+
cmd << "--sync" << resource_name
263263

264264
if self.class.yaourt?
265265
yaourt(*cmd)

spec/unit/provider/package/pacman_spec.rb

+29-29
Original file line numberDiff line numberDiff line change
@@ -165,58 +165,58 @@
165165

166166
describe "when purging" do
167167
it "should call pacman to remove the right package and configs quietly" do
168-
args = ["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "-R", "--nosave", resource[:name]]
168+
args = ["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "--remove", "--nosave", resource[:name]]
169169
expect(executor).to receive(:execute).with(args, no_extra_options).and_return("")
170170
provider.purge
171171
end
172172
end
173173

174174
describe "when uninstalling" do
175175
it "should call pacman to remove the right package quietly" do
176-
args = ["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "-R", resource[:name]]
176+
args = ["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "--remove", resource[:name]]
177177
expect(executor).to receive(:execute).with(args, no_extra_options).and_return("")
178178
provider.uninstall
179179
end
180180

181181
it "should call yaourt to remove the right package quietly" do
182182
without_partial_double_verification do
183183
allow(described_class).to receive(:yaourt?).and_return(true)
184-
args = ["--noconfirm", "--noprogressbar", "-R", resource[:name]]
184+
args = ["--noconfirm", "--noprogressbar", "--remove", resource[:name]]
185185
expect(provider).to receive(:yaourt).with(*args)
186186
provider.uninstall
187187
end
188188
end
189189

190190
it "adds any uninstall_options" do
191191
resource[:uninstall_options] = ['-x', {'--arg' => 'value'}]
192-
args = ["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "-x", "--arg=value", "-R", resource[:name]]
192+
args = ["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "-x", "--arg=value", "--remove", resource[:name]]
193193
expect(executor).to receive(:execute).with(args, no_extra_options).and_return("")
194194
provider.uninstall
195195
end
196196

197197
it "should recursively remove packages when given a package group" do
198198
allow(described_class).to receive(:group?).and_return(true)
199-
args = ["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "-R", "-s", resource[:name]]
199+
args = ["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "--remove", "-s", resource[:name]]
200200
expect(executor).to receive(:execute).with(args, no_extra_options).and_return("")
201201
provider.uninstall
202202
end
203203
end
204204

205205
describe "when querying" do
206206
it "should query pacman" do
207-
expect(executor).to receive(:execpipe).with(["/usr/bin/pacman", '-Q'])
208-
expect(executor).to receive(:execpipe).with(["/usr/bin/pacman", '-Sgg', 'package'])
207+
expect(executor).to receive(:execpipe).with(["/usr/bin/pacman", '--query'])
208+
expect(executor).to receive(:execpipe).with(["/usr/bin/pacman", '--sync', '-gg', 'package'])
209209
provider.query
210210
end
211211

212212
it "should return the version" do
213213
expect(executor).to receive(:execpipe).
214-
with(["/usr/bin/pacman", "-Q"]).and_yield(<<EOF)
214+
with(["/usr/bin/pacman", "--query"]).and_yield(<<EOF)
215215
otherpackage 1.2.3.4
216216
package 1.01.3-2
217217
yetanotherpackage 1.2.3.4
218218
EOF
219-
expect(executor).to receive(:execpipe).with(['/usr/bin/pacman', '-Sgg', 'package']).and_yield('')
219+
expect(executor).to receive(:execpipe).with(['/usr/bin/pacman', '--sync', '-gg', 'package']).and_yield('')
220220

221221
expect(provider.query).to eq({ :name => 'package', :ensure => '1.01.3-2', :provider => :pacman, })
222222
end
@@ -234,8 +234,8 @@
234234

235235
describe 'when querying a group' do
236236
before :each do
237-
expect(executor).to receive(:execpipe).with(['/usr/bin/pacman', '-Q']).and_yield('foo 1.2.3')
238-
expect(executor).to receive(:execpipe).with(['/usr/bin/pacman', '-Sgg', 'package']).and_yield('package foo')
237+
expect(executor).to receive(:execpipe).with(['/usr/bin/pacman', '--query']).and_yield('foo 1.2.3')
238+
expect(executor).to receive(:execpipe).with(['/usr/bin/pacman', '--sync', '-gg', 'package']).and_yield('package foo')
239239
end
240240

241241
it 'should warn when allow_virtual is false' do
@@ -254,14 +254,14 @@
254254

255255
describe "when determining instances" do
256256
it "should retrieve installed packages and groups" do
257-
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '-Q'])
258-
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '-Sgg'])
257+
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '--query'])
258+
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '--sync', '-gg'])
259259
described_class.instances
260260
end
261261

262262
it "should return installed packages" do
263-
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '-Q']).and_yield(StringIO.new("package1 1.23-4\npackage2 2.00\n"))
264-
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '-Sgg']).and_yield("")
263+
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '--query']).and_yield(StringIO.new("package1 1.23-4\npackage2 2.00\n"))
264+
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '--sync', '-gg']).and_yield("")
265265
instances = described_class.instances
266266

267267
expect(instances.length).to eq(2)
@@ -280,11 +280,11 @@
280280
end
281281

282282
it "should return completely installed groups with a virtual version together with packages" do
283-
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '-Q']).and_yield(<<EOF)
283+
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '--query']).and_yield(<<EOF)
284284
package1 1.00
285285
package2 1.00
286286
EOF
287-
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '-Sgg']).and_yield(<<EOF)
287+
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '--sync', '-gg']).and_yield(<<EOF)
288288
group1 package1
289289
group1 package2
290290
EOF
@@ -310,10 +310,10 @@
310310
end
311311

312312
it "should not return partially installed packages" do
313-
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '-Q']).and_yield(<<EOF)
313+
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '--query']).and_yield(<<EOF)
314314
package1 1.00
315315
EOF
316-
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '-Sgg']).and_yield(<<EOF)
316+
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '--sync', '-gg']).and_yield(<<EOF)
317317
group1 package1
318318
group1 package2
319319
EOF
@@ -329,7 +329,7 @@
329329
end
330330

331331
it 'should sort package names for installed groups' do
332-
expect(described_class).to receive(:execpipe).with(['/usr/bin/pacman', '-Sgg', 'group1']).and_yield(<<EOF)
332+
expect(described_class).to receive(:execpipe).with(['/usr/bin/pacman', '--sync', '-gg', 'group1']).and_yield(<<EOF)
333333
group1 aa
334334
group1 b
335335
group1 a
@@ -360,7 +360,7 @@
360360
it "should get query pacman for the latest version" do
361361
expect(executor).to receive(:execute).
362362
ordered.
363-
with(['/usr/bin/pacman', '-Sp', '--print-format', '%v', resource[:name]], no_extra_options).
363+
with(['/usr/bin/pacman', '--sync', '--print', '--print-format', '%v', resource[:name]], no_extra_options).
364364
and_return("")
365365

366366
provider.latest
@@ -374,7 +374,7 @@
374374

375375
it "should return a virtual group version when resource is a package group" do
376376
allow(described_class).to receive(:group?).and_return(true)
377-
expect(executor).to receive(:execute).with(['/usr/bin/pacman', '-Sp', '--print-format', '%n %v', resource[:name]], no_extra_options).ordered.
377+
expect(executor).to receive(:execute).with(['/usr/bin/pacman', '--sync', '--print', '--print-format', '%n %v', resource[:name]], no_extra_options).ordered.
378378
and_return(<<EOF)
379379
package2 1.0.1
380380
package1 1.0.0
@@ -389,17 +389,17 @@
389389
end
390390

391391
it 'should return false on non-zero pacman exit' do
392-
allow(executor).to receive(:execute).with(['/usr/bin/pacman', '-Sg', 'git'], {:failonfail => true, :combine => true, :custom_environment => {}}).and_raise(Puppet::ExecutionFailure, 'error')
392+
allow(executor).to receive(:execute).with(['/usr/bin/pacman', '--sync', '--groups', 'git'], {:failonfail => true, :combine => true, :custom_environment => {}}).and_raise(Puppet::ExecutionFailure, 'error')
393393
expect(described_class.group?('git')).to eq(false)
394394
end
395395

396396
it 'should return false on empty pacman output' do
397-
allow(executor).to receive(:execute).with(['/usr/bin/pacman', '-Sg', 'git'], {:failonfail => true, :combine => true, :custom_environment => {}}).and_return('')
397+
allow(executor).to receive(:execute).with(['/usr/bin/pacman', '--sync', '--groups', 'git'], {:failonfail => true, :combine => true, :custom_environment => {}}).and_return('')
398398
expect(described_class.group?('git')).to eq(false)
399399
end
400400

401401
it 'should return true on non-empty pacman output' do
402-
allow(executor).to receive(:execute).with(['/usr/bin/pacman', '-Sg', 'vim-plugins'], {:failonfail => true, :combine => true, :custom_environment => {}}).and_return('vim-plugins vim-a')
402+
allow(executor).to receive(:execute).with(['/usr/bin/pacman', '--sync', '--groups', 'vim-plugins'], {:failonfail => true, :combine => true, :custom_environment => {}}).and_return('vim-plugins vim-a')
403403
expect(described_class.group?('vim-plugins')).to eq(true)
404404
end
405405
end
@@ -409,21 +409,21 @@
409409
let(:groups) { [['foo package1'], ['foo package2'], ['bar package3'], ['bar package4'], ['baz package5']] }
410410

411411
it 'should raise an error on non-zero pacman exit without a filter' do
412-
expect(executor).to receive(:open).with('| /usr/bin/pacman -Sgg 2>&1').and_return('error!')
412+
expect(executor).to receive(:open).with('| /usr/bin/pacman --sync -gg 2>&1').and_return('error!')
413413
expect(Puppet::Util::Execution).to receive(:exitstatus).and_return(1)
414414
expect { described_class.get_installed_groups(installed_packages) }.to raise_error(Puppet::ExecutionFailure, 'error!')
415415
end
416416

417417
it 'should return empty groups on non-zero pacman exit with a filter' do
418-
expect(executor).to receive(:open).with('| /usr/bin/pacman -Sgg git 2>&1').and_return('')
418+
expect(executor).to receive(:open).with('| /usr/bin/pacman --sync -gg git 2>&1').and_return('')
419419
expect(Puppet::Util::Execution).to receive(:exitstatus).and_return(1)
420420
expect(described_class.get_installed_groups(installed_packages, 'git')).to eq({})
421421
end
422422

423423
it 'should return empty groups on empty pacman output' do
424424
pipe = double()
425425
expect(pipe).to receive(:each_line)
426-
expect(executor).to receive(:open).with('| /usr/bin/pacman -Sgg 2>&1').and_yield(pipe).and_return('')
426+
expect(executor).to receive(:open).with('| /usr/bin/pacman --sync -gg 2>&1').and_yield(pipe).and_return('')
427427
expect(Puppet::Util::Execution).to receive(:exitstatus).and_return(0)
428428
expect(described_class.get_installed_groups(installed_packages)).to eq({})
429429
end
@@ -433,7 +433,7 @@
433433
pipe_expectation = receive(:each_line)
434434
groups.each { |group| pipe_expectation = pipe_expectation.and_yield(*group) }
435435
expect(pipe).to pipe_expectation
436-
expect(executor).to receive(:open).with('| /usr/bin/pacman -Sgg 2>&1').and_yield(pipe).and_return('')
436+
expect(executor).to receive(:open).with('| /usr/bin/pacman --sync -gg 2>&1').and_yield(pipe).and_return('')
437437
expect(Puppet::Util::Execution).to receive(:exitstatus).and_return(0)
438438
expect(described_class.get_installed_groups(installed_packages)).to eq({'foo' => 'package1 1.0, package2 2.0'})
439439
end

0 commit comments

Comments
 (0)