Skip to content

Commit d0d28d8

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 c879297 commit d0d28d8

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
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

+35-35
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
end
2727

2828
it "should call pacman to install the right package quietly when yaourt is not installed" do
29-
args = ['--noconfirm', '--needed', '--noprogressbar', '-S', resource[:name]]
29+
args = ['--noconfirm', '--needed', '--noprogressbar', '--sync', resource[:name]]
3030
expect(provider).to receive(:pacman).at_least(:once).with(*args).and_return('')
3131
provider.install
3232
end
3333

3434
it "should call yaourt to install the right package quietly when yaourt is installed" do
3535
without_partial_double_verification do
3636
allow(described_class).to receive(:yaourt?).and_return(true)
37-
args = ['--noconfirm', '--needed', '--noprogressbar', '-S', resource[:name]]
37+
args = ['--noconfirm', '--needed', '--noprogressbar', '--sync', resource[:name]]
3838
expect(provider).to receive(:yaourt).at_least(:once).with(*args).and_return('')
3939
provider.install
4040
end
@@ -70,15 +70,15 @@
7070
end
7171

7272
it "should call pacman to install the right package quietly when yaourt is not installed" do
73-
args = ['--noconfirm', '--needed', '--noprogressbar', '-x', '--arg=value', '-S', resource[:name]]
73+
args = ['--noconfirm', '--needed', '--noprogressbar', '-x', '--arg=value', '--sync', resource[:name]]
7474
expect(provider).to receive(:pacman).at_least(:once).with(*args).and_return('')
7575
provider.install
7676
end
7777

7878
it "should call yaourt to install the right package quietly when yaourt is installed" do
7979
without_partial_double_verification do
8080
expect(described_class).to receive(:yaourt?).and_return(true)
81-
args = ['--noconfirm', '--needed', '--noprogressbar', '-x', '--arg=value', '-S', resource[:name]]
81+
args = ['--noconfirm', '--needed', '--noprogressbar', '-x', '--arg=value', '--sync', resource[:name]]
8282
expect(provider).to receive(:yaourt).at_least(:once).with(*args).and_return('')
8383
provider.install
8484
end
@@ -98,7 +98,7 @@
9898
resource[:source] = source
9999

100100
expect(executor).to receive(:execute).
101-
with(include("-U") & include(source), no_extra_options).
101+
with(include("--update") & include(source), no_extra_options).
102102
ordered.
103103
and_return("")
104104

@@ -116,7 +116,7 @@
116116

117117
it "should install from the path segment of the URL" do
118118
expect(executor).to receive(:execute).
119-
with(include("-U") & include(actual_file_path), no_extra_options).
119+
with(include("--update") & include(actual_file_path), no_extra_options).
120120
ordered.
121121
and_return("")
122122

@@ -159,58 +159,58 @@
159159

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

168168
describe "when uninstalling" do
169169
it "should call pacman to remove the right package quietly" do
170-
args = ["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "-R", resource[:name]]
170+
args = ["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "--remove", resource[:name]]
171171
expect(executor).to receive(:execute).with(args, no_extra_options).and_return("")
172172
provider.uninstall
173173
end
174174

175175
it "should call yaourt to remove the right package quietly" do
176176
without_partial_double_verification do
177177
allow(described_class).to receive(:yaourt?).and_return(true)
178-
args = ["--noconfirm", "--noprogressbar", "-R", resource[:name]]
178+
args = ["--noconfirm", "--noprogressbar", "--remove", resource[:name]]
179179
expect(provider).to receive(:yaourt).with(*args)
180180
provider.uninstall
181181
end
182182
end
183183

184184
it "adds any uninstall_options" do
185185
resource[:uninstall_options] = ['-x', {'--arg' => 'value'}]
186-
args = ["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "-x", "--arg=value", "-R", resource[:name]]
186+
args = ["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "-x", "--arg=value", "--remove", resource[:name]]
187187
expect(executor).to receive(:execute).with(args, no_extra_options).and_return("")
188188
provider.uninstall
189189
end
190190

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

199199
describe "when querying" do
200200
it "should query pacman" do
201-
expect(executor).to receive(:execpipe).with(["/usr/bin/pacman", '-Q'])
202-
expect(executor).to receive(:execpipe).with(["/usr/bin/pacman", '-Sgg', 'package'])
201+
expect(executor).to receive(:execpipe).with(["/usr/bin/pacman", '--query'])
202+
expect(executor).to receive(:execpipe).with(["/usr/bin/pacman", '--sync', '-gg', 'package'])
203203
provider.query
204204
end
205205

206206
it "should return the version" do
207207
expect(executor).to receive(:execpipe).
208-
with(["/usr/bin/pacman", "-Q"]).and_yield(<<EOF)
208+
with(["/usr/bin/pacman", "--query"]).and_yield(<<EOF)
209209
otherpackage 1.2.3.4
210210
package 1.01.3-2
211211
yetanotherpackage 1.2.3.4
212212
EOF
213-
expect(executor).to receive(:execpipe).with(['/usr/bin/pacman', '-Sgg', 'package']).and_yield('')
213+
expect(executor).to receive(:execpipe).with(['/usr/bin/pacman', '--sync', '-gg', 'package']).and_yield('')
214214

215215
expect(provider.query).to eq({ :name => 'package', :ensure => '1.01.3-2', :provider => :pacman, })
216216
end
@@ -228,8 +228,8 @@
228228

229229
describe 'when querying a group' do
230230
before :each do
231-
expect(executor).to receive(:execpipe).with(['/usr/bin/pacman', '-Q']).and_yield('foo 1.2.3')
232-
expect(executor).to receive(:execpipe).with(['/usr/bin/pacman', '-Sgg', 'package']).and_yield('package foo')
231+
expect(executor).to receive(:execpipe).with(['/usr/bin/pacman', '--query']).and_yield('foo 1.2.3')
232+
expect(executor).to receive(:execpipe).with(['/usr/bin/pacman', '--sync', '-gg', 'package']).and_yield('package foo')
233233
end
234234

235235
it 'should warn when allow_virtual is false' do
@@ -248,14 +248,14 @@
248248

249249
describe "when determining instances" do
250250
it "should retrieve installed packages and groups" do
251-
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '-Q'])
252-
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '-Sgg'])
251+
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '--query'])
252+
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '--sync', '-gg'])
253253
described_class.instances
254254
end
255255

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

261261
expect(instances.length).to eq(2)
@@ -274,11 +274,11 @@
274274
end
275275

276276
it "should return completely installed groups with a virtual version together with packages" do
277-
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '-Q']).and_yield(<<EOF)
277+
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '--query']).and_yield(<<EOF)
278278
package1 1.00
279279
package2 1.00
280280
EOF
281-
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '-Sgg']).and_yield(<<EOF)
281+
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '--sync', '-gg']).and_yield(<<EOF)
282282
group1 package1
283283
group1 package2
284284
EOF
@@ -304,10 +304,10 @@
304304
end
305305

306306
it "should not return partially installed packages" do
307-
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '-Q']).and_yield(<<EOF)
307+
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '--query']).and_yield(<<EOF)
308308
package1 1.00
309309
EOF
310-
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '-Sgg']).and_yield(<<EOF)
310+
expect(described_class).to receive(:execpipe).with(["/usr/bin/pacman", '--sync', '-gg']).and_yield(<<EOF)
311311
group1 package1
312312
group1 package2
313313
EOF
@@ -323,7 +323,7 @@
323323
end
324324

325325
it 'should sort package names for installed groups' do
326-
expect(described_class).to receive(:execpipe).with(['/usr/bin/pacman', '-Sgg', 'group1']).and_yield(<<EOF)
326+
expect(described_class).to receive(:execpipe).with(['/usr/bin/pacman', '--sync', '-gg', 'group1']).and_yield(<<EOF)
327327
group1 aa
328328
group1 b
329329
group1 a
@@ -354,7 +354,7 @@
354354
it "should get query pacman for the latest version" do
355355
expect(executor).to receive(:execute).
356356
ordered.
357-
with(['/usr/bin/pacman', '-Sp', '--print-format', '%v', resource[:name]], no_extra_options).
357+
with(['/usr/bin/pacman', '--sync', '--print', '--print-format', '%v', resource[:name]], no_extra_options).
358358
and_return("")
359359

360360
provider.latest
@@ -368,7 +368,7 @@
368368

369369
it "should return a virtual group version when resource is a package group" do
370370
allow(described_class).to receive(:group?).and_return(true)
371-
expect(executor).to receive(:execute).with(['/usr/bin/pacman', '-Sp', '--print-format', '%n %v', resource[:name]], no_extra_options).ordered.
371+
expect(executor).to receive(:execute).with(['/usr/bin/pacman', '--sync', '--print', '--print-format', '%n %v', resource[:name]], no_extra_options).ordered.
372372
and_return(<<EOF)
373373
package2 1.0.1
374374
package1 1.0.0
@@ -383,17 +383,17 @@
383383
end
384384

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

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

395395
it 'should return true on non-empty pacman output' do
396-
allow(executor).to receive(:execute).with(['/usr/bin/pacman', '-Sg', 'vim-plugins'], {:failonfail => true, :combine => true, :custom_environment => {}}).and_return('vim-plugins vim-a')
396+
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')
397397
expect(described_class.group?('vim-plugins')).to eq(true)
398398
end
399399
end
@@ -403,21 +403,21 @@
403403
let(:groups) { [['foo package1'], ['foo package2'], ['bar package3'], ['bar package4'], ['baz package5']] }
404404

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

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

417417
it 'should return empty groups on empty pacman output' do
418418
pipe = double()
419419
expect(pipe).to receive(:each_line)
420-
expect(executor).to receive(:open).with('| /usr/bin/pacman -Sgg 2>&1').and_yield(pipe).and_return('')
420+
expect(executor).to receive(:open).with('| /usr/bin/pacman --sync -gg 2>&1').and_yield(pipe).and_return('')
421421
expect(Puppet::Util::Execution).to receive(:exitstatus).and_return(0)
422422
expect(described_class.get_installed_groups(installed_packages)).to eq({})
423423
end
@@ -427,7 +427,7 @@
427427
pipe_expectation = receive(:each_line)
428428
groups.each { |group| pipe_expectation = pipe_expectation.and_yield(*group) }
429429
expect(pipe).to pipe_expectation
430-
expect(executor).to receive(:open).with('| /usr/bin/pacman -Sgg 2>&1').and_yield(pipe).and_return('')
430+
expect(executor).to receive(:open).with('| /usr/bin/pacman --sync -gg 2>&1').and_yield(pipe).and_return('')
431431
expect(Puppet::Util::Execution).to receive(:exitstatus).and_return(0)
432432
expect(described_class.get_installed_groups(installed_packages)).to eq({'foo' => 'package1 1.0, package2 2.0'})
433433
end

0 commit comments

Comments
 (0)