about summary refs log tree commit diff
path: root/Completion/Solaris/Command/_pkg5
blob: bcd4e3daf62f411de60d1ccca9aca10bf8c673f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
#compdef pkg

_pkg5_pkgs() {
	local cache_policy cache_id=pkg5_installed_pkgs:$HOST:${pkg5_root//\//+}
	typeset -a -g _pkg5_installed_pkgs

	zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
	if [[ -z "$cache_policy" ]]; then
		zstyle ":completion:${curcontext}:" cache-policy _pkg5_installed_caching_policy
	fi

	if ( [[ $#_pkg5_installed_pkgs -eq 0 ]] || _cache_invalid $cache_id ) && ! _retrieve_cache $cache_id; then
		_pkg5_installed_pkgs=( $(
			pkg -R $pkg5_root list -H | while read pkg junk; do
				pkga=( ${(s:/:)pkg} )
				for i in {1..$#pkga}; do
					print ${(j:/:)${pkga[$i,-1]}}
				done
			done) )
		_store_cache $cache_id _pkg5_installed_pkgs
	fi

	compadd "$@" - ${_pkg5_installed_pkgs}
}

_pkg5_pkgs_a() {
	local cache_policy cache_id=pkg5_known_pkgs:$HOST:${pkg5_root//\//+}
	typeset -a -g _pkg5_known_pkgs

	zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
	if [[ -z "$cache_policy" ]]; then
		zstyle ":completion:${curcontext}:" cache-policy _pkg5_known_caching_policy
	fi

	if ( [[ $#_pkg5_known_pkgs -eq 0 ]] || _cache_invalid $cache_id ) && ! _retrieve_cache $cache_id; then
		_pkg5_known_pkgs=( $(
			pkg -R $pkg5_root list -aH --no-refresh | while read pkg junk; do
				pkga=( ${(s:/:)pkg} )
				for i in {1..$#pkga}; do
					print ${(j:/:)${pkga[$i,-1]}}
				done
			done) )
		_store_cache $cache_id _pkg5_known_pkgs
	fi

	compadd "$@" - ${_pkg5_known_pkgs}
}

_pkg5_avoided_pkgs() {
	compadd "$@" - $(pkg -R $pkg5_root unavoid)
}

_pkg5_pubs() {
	compadd "$@" - $(pkg -R $pkg5_root publisher -H | awk '{print $1}')
}

_pkg5_variants() {
	compadd "$@" - $(pkg -R $pkg5_root variant -H | awk '{print $1}')
}

_pkg5_facets() {
	compadd "$@" - $(pkg -R $pkg5_root facet -H | awk '{print $1}')
}

_pkg5_known_caching_policy() {
	[[ $pkg5_root/var/pkg/state/known/catalog.attrs -nt "$1" ]]
}

_pkg5_installed_caching_policy() {
	[[ $pkg5_root/var/pkg/state/installed/catalog.attrs -nt "$1" ]]
}

_pkg5() {
	local expl context state line pkg5_root prop
	typeset -A opt_args
	local -a subcmds pkg5_actions pkg5_cattr pkg5_sattr be_opts
	local -a publisher_properties image_properties certs

	subcmds=(
		install uninstall list update refresh version help
		info search verify fix revert contents image-create
		{change-,}{variant,facet} avoid unavoid history
		{{un,}set-,}property {add,remove}-property-value
		{{un,}set-,}publisher purge-history rebuild-index
		update-format freeze unfreeze {{un,}set-,}mediator
	)

	pkg5_actions=(
		set depend dir driver file group hardlink legacy license link
		signature unknown user
	)

	# Pseudo attributes for the contents subcommand
	pkg5_cattr=(
		action.hash action.key action.name action.raw
		pkg.fmri pkg.name pkg.publisher pkg.shortfmri
	)

	# Pseudo attributes for the search subcommand
	pkg5_sattr=(
		$pkg5_cattr search.match search.match_type
	)

	publisher_properties=(
		"signature-policy:value:(ignore verify require-signatures require-names)"
		"signature-required-names:value:"
	)

	image_properties=(
	    "be-policy:value:(default always-new create-backup when-required)"
	    "ca-path:value:_path_files -/"
	    "check-certificate-revocation:value:(true false)"
	    "flush-content-cache-on-success:value:(true false)"
	    "mirror-discovery:value:(true false)"
	    "send-uuid:value:(true false)"
	    "signature-policy:value:(ignore verify require-signatures require-names)"
	    "signature-required-names:value:"
	    "trust-anchor-directory:value:_path_files -/"
	    "use-system-repo:value:(true false)"
	)

	if [[ $service == "pkg" ]]; then
		_arguments -C -A "-*" \
			'(-\? --help)'{-\?,--help}'[Help]' \
			'-R[Root directory]:directory:_path_files -/' \
			'*::command:->subcmd' && return 0

		if (( CURRENT == 1 )); then
			_wanted commands expl "pkg subcommand" compadd -a subcmds
			return
		fi
		service="$words[1]"
		curcontext="${curcontext%:*}=$service:"
	fi

	pkg5_root=${${${opt_args[-R]}:-$PKG_IMAGE}:-/}

	certs=( $(pkg -R $pkg5_root property -H ca-path | awk '{print $2}')/* )

	# Options common to subcommands which might have to deal with BEs.
	# Note that --backup-be-name needs to precede --be-name in order to
	# ensure that completion sees "--b" as being ambiguous.
	be_opts=(
		"(--require-new-be)--deny-new-be[Fail the operation if a new BE would be required]"
		"(--deny-new-be)--require-new-be[Force a new BE to be created]"
		"--backup-be-name[Specify the name for the backup BE]:BE name: "
		"--be-name[Specify a BE name]:BE name: "
		"--no-be-activate[Don't activate the new BE]"
		"(--require-backup-be)--no-backup-be[Don't leave behind a backup BE]"
		"(--no-backup-be)--require-backup-be[Force leaving behind a backup BE]"
	)

	case $service in
	("install")
		_arguments -A "-*" \
			'-n[Dry run]' \
			'-q[Quiet]' \
			'-v[Verbose]' \
			'-g[Specify additional source of packages]:source:_path_files -/' \
			"--accept[Accept all licenses]" \
			"--licenses[Display all licenses]" \
			"--reject[Specify an FMRI to exclude from the result]:fmri:_pkg5_pkgs" \
			"--no-refresh[Don't refresh catalogs]" \
			"--no-index[Don't reindex search database]" \
			$be_opts \
			'*:package:_pkg5_pkgs_a'
		;;

	("uninstall")
		_arguments -A "-*" \
			'-n[Dry run]' \
			'-q[Quiet]' \
			'-v[Verbose]' \
			$be_opts \
			"--no-index[Don't reindex search database]" \
			'*:package:_pkg5_pkgs'
		;;

	("update")
		_arguments -A "-*" \
			"-f[Don't check for pkg(5) updates]" \
			'-n[Dry run]' \
			'-q[Quiet]' \
			'-v[Verbose]' \
			'-g[Specify additional source of packages]:source:_path_files -/' \
			"--accept[Accept all licenses]" \
			"--licenses[Display all licenses]" \
			$be_opts \
			"--reject[Specify an FMRI to exclude from the result]:fmri:_pkg5_pkgs" \
			"--no-refresh[Don't refresh catalogs]" \
			"--no-index[Don't reindex search database]" \
			'*:package:_pkg5_pkgs'
		;;

	("list")
		_arguments -A "-*" \
			'-H[Omit headers]' \
			'-a[Show not-installed packages]' \
			'-f[Show all versions]' \
			'-g[Specify additional source of packages]:source:_path_files -/' \
			'-n[Show newest versions]' \
			'-s[Show summaries]' \
			'-u[Show upgradable versions]' \
			'-v[Show verbose pkg: FMRIs]' \
			"--no-refresh[Don't refresh catalogs]" \
			'*:package:_pkg5_pkgs_a'
		;;

	("refresh")
		_arguments -A "-*" \
			"--full[Full refresh]" \
			'*:publisher:_pkg5_pubs'
		;;

	("info")
		_arguments -A "-*" \
			'--license[Display license text(s)]' \
			'(-r)-l[Installed package]' \
			'(-l)-r[Uninstalled package; fetch info from depot]:*:package:_pkg5_pkgs_a' \
			'*:package:_pkg5_pkgs'
		;;

	("search")
		_arguments -A "-*" \
			"(-p)-a[Show matching actions]" \
			'-l[Local search]' \
			'(-a)-p[Show packages]' \
			'-r[Remote search]' \
			'-H[Omit headers]' \
			'-I[Case sensitive search]' \
			'-s[Depot URI]' \
			'*-o[Attribute output]:attributes:_values -s , "attribute" $pkg5_sattr' \
			':query:'
		;;

	("verify")
		_arguments -A "-*" \
			'-H[Omit headers]' \
			'-q[Quiet]' \
			'-v[Verbose]' \
			'*:package:_pkg5_pkgs'
		;;

	("fix")
		_arguments -A "-*" \
			'--accept[Accept all licenses]' \
			'--licenses[Display all licenses]' \
			'*:package:_pkg5_pkgs'
		;;

	("revert")
		_arguments -A "-*" \
			'-n[Dry run]' \
			'-v[Verbose]' \
			'--tagged[Revert all tagged files]:tag:' \
			$be_opts \
			"--no-refresh[Don't refresh catalogs]" \
			"--no-index[Don't reindex search database]" \
			'*:file:_path_files'
		;;

	("contents")
		_arguments -A "-*" \
			'-H[Omit headers]' \
			'-m[Print raw manifests]' \
			'*-a[Attribute matching]:attribute=pattern:' \
			'*-o[Attribute output]:attributes:_values -s , "attribute" $pkg5_cattr' \
			'*-s[Sort key]:attribute:' \
			'*-t[Action type]:action:_values -s , "action" $pkg5_actions' \
			'-r[Fetch manifests from depot]:*:package:_pkg5_pkgs_a' \
			'*:package:_pkg5_pkgs'
		;;

	("image-create")
		_arguments -A "-*" \
			'(-f --force)'{-f,--force}'[Force image creation]' \
			'(-F --full -P --partial -U --user)'{-F,--full}'[Full image]' \
			'(-F --full -P --partial -U --user)'{-P,--partial}'[Partial image]' \
			'(-F --full -P --partial -U --user)'{-U,--user}'[User image]' \
			'(-z --zone)'{-z,--zone}'[Zoned image]' \
			'-k[Path to SSL key]:file:_path_files' \
			'-c[Path to SSL cert]:file:_path_files' \
			"--no-refresh[Don't refresh catalogs]" \
			"*--variant[Specify image variants]:variant=instance:" \
			"*--facet[Specify image facets]:facet=True/False:" \
			'(-p --publisher)'{-p,--publisher}'[Specify publisher]:prefix=URI:' \
			':directory:_path_files -/'
		;;

	("change-variant")
		_arguments -A "-*" \
			'-n[Dry run]' \
			'-q[Quiet'] \
			'-v[Verbose'] \
			'-g[Specify additional source of packages]:source:_path_files -/' \
			'--accept[Accept all licenses]' \
			'--licenses[Display all licenses]' \
			$be_opts \
			"*:variant:_values -s , 'variant' $(pkg -R $pkg5_root variant -H | awk '{print $1}')" \
		;;

	("change-facet")
		_arguments -A "-*" \
			'-n[Dry run]' \
			'-q[Quiet'] \
			'-v[Verbose'] \
			'-g[Specify additional source of packages]:source:_path_files -/' \
			'--accept[Accept all licenses]' \
			'--licenses[Display all licenses]' \
			$be_opts \
			"*:facet:_values -s , 'facet' $(pkg -R $pkg5_root facet -H | awk '{print $1}')" \
		;;

	("variant")
		_arguments -A "-*" \
			'-H[Omit headers]' \
			'*:variant:_pkg5_variants'
		;;

	("facet")
		_arguments -A "-*" \
			'-H[Omit headers]' \
			'*:facet:_pkg5_facets'
		;;

	("avoid")
		_arguments -A "-*" \
			'*:package:_pkg5_pkgs_a'
		;;

	("unavoid")
		_arguments -A "-*" \
			'*:package:_pkg5_avoided_pkgs'
		;;

	("set-property")
		_arguments -A "-*" \
			':property:_values "property" $image_properties' \
			':value:'
		;;

	("add-property-value")
		_arguments -A "-*" \
			':property:_values "property" $image_properties' \
			':value:'
		;;

	("remove-property-value")
		_arguments -A "-*" \
			':property:(${image_properties%%\:*})' \
			':value:'
		;;

	("unset-property")
		_arguments -A "-*" \
			'*:property:(${image_properties%%\:*})'
		;;

	("property")
		_arguments -A "-*" \
			'-H[Omit headers]' \
			'*:property:(${image_properties%%\:*})'
		;;

	("set-publisher")
		_arguments -A "-*" \
			'-P[Make preferred]' \
			'(-e --enable)'{-e,--enable}'[Enable publisher]' \
			'(-d --disable)'{-d,--disable}'[Disable publisher]' \
			'(-g --add-origin)'{-g,--add-origin}'[Add origin URI]:uri:' \
			'(-G --remove-origin)'{-G,--remove-origin}'[Remove origin URI]:uri:' \
			'(-m --add-mirror)'{-m,--add-mirror}'[Add mirror URI]:uri:' \
			'(-M --remove-mirror)'{-M,--remove-mirror}'[Remove mirror URI]:uri:' \
			'-p[Repository URI]:url:' \
			"--no-refresh[Don't refresh catalogs]" \
			'--reset-uuid[Reset the image UUID for this publisher]' \
			'--sticky[Make this publisher sticky]' \
			'--non-sticky[Make this publisher non-sticky]' \
			'--search-after[Set publisher search-order]:publisher:_pkg5_pubs' \
			'--search-before[Set publisher search-order]:publisher:_pkg5_pubs' \
			'--approve-ca-cert[Add trusted CA certificate]:CA cert path:_path_files' \
			'--revoke-ca-cert[Revoke CA certificate]:CA cert hash:(${${certs#/etc/openssl/certs/}%.0})' \
			'--unset-ca-cert[Remove trusted CA certificate]:CA cert hash:' \
			'--set-property[Set publisher property]:property:_values "property" $publisher_properties' \
			'--unset-property[Remove publisher property]:property:(${publisher_properties%%\:*})' \
			'--add-property-value[Add publisher property value]:property:_values "property" $publisher_properties' \
			'--remove-property-value[Remove publisher property value]:property:(${publisher_properties%%\:*})' \
			':publisher:_pkg5_pubs'
		;;

	("unset-publisher")
		_arguments -A "-*" \
			'*:publisher:_pkg5_pubs'
		;;

	("publisher")
		_arguments -A "-*" \
			'-H[Omit headers]' \
			'-P[Display only preferred publisher]' \
			'-n[Display only enabled publishers]' \
			'*:publisher:_pkg5_pubs'
		;;

	("history")
		local -a hist_columns
		hist_columns=(
			"be" "be_uuid" "client" "client_ver" "command" "finish"
			"id" "new_be" "new_be_uuid" "operation" "outcome"
			"reason" "snapshot" "start" "time" "user"
		)
		_arguments -A "-*" \
			'-H[Omit headers]' \
			'-l[Long history]' \
			'-n[Last n records]:number:' \
			'-o[Column]:number:_values -s , "column" $hist_columns' \
			'-t[Time range]'
		;;

	("freeze"|"unfreeze")
		;;

	("mediator"|"set-mediator"|"unset-mediator")
		;;

	(*)
		_message "unknown pkg subcommand: $service" ;;

	esac
}

_pkg5 "$@"