hostnamectl: say that tags can be removed by glob

This commit is contained in:
Zbigniew Jędrzejewski-Szmek committed 2026-10-30 16:56:37 +01:00
1 parent bd80a56ebd
commit d73ba670fc
2 files changed
+23 -7

No files matched your search

+9 -6
View File
@@ -180,12 +180,15 @@
<para>Alternatively, each argument may be prefixed with <literal>+</literal> or <literal>-</literal>
to incrementally update the configured tags rather than replacing them: an argument prefixed with
<literal>+</literal> adds all of its (colon-separated) tags to the list, one prefixed with
<literal>-</literal> removes them. For example, <command>hostnamectl tags +foo:bar -quux:ooo</command>
adds the tags <literal>foo</literal> and <literal>bar</literal> and removes <literal>quux</literal>
and <literal>ooo</literal>. The prefix applies to the whole argument, i.e. to every tag listed within
it. Adding a <literal><replaceable>key</replaceable>=<replaceable>value</replaceable></literal> tag
replaces any value previously assigned to the same key. Prefixed and unprefixed arguments may not be
combined in a single invocation.</para>
<literal>-</literal> specifies a removal pattern. For example, <command>hostnamectl tags +foo:bar
-quux:ooo=*</command> adds the tags <literal>foo</literal> and <literal>bar</literal> and removes
<literal>quux</literal> and any assignment of <literal>ooo=</literal>. The prefix applies to the
whole argument, i.e. to every tag listed within it. Adding a
<literal><replaceable>key</replaceable>=<replaceable>value</replaceable></literal> tag replaces any
value previously assigned to the same key. Prefixed and unprefixed arguments may not be combined in a
single invocation. Removal patterns may use shell-style globbing to remove any matching tags,
<citerefentry project='man-pages'><refentrytitle>glob</refentrytitle><manvolnum>7</manvolnum></citerefentry>.
</para>
<para>If <option>--apply</option> is specified, no <replaceable>TAG</replaceable> arguments may be
given. Instead, <filename>systemd-hostnamed</filename> is asked to apply the tag configuration
+14 -1
View File
@@ -474,7 +474,20 @@ testcase_tags() {
hostnamectl tags +foo=b
assert_eq "$(hostnamectl tags)" "foo:foo=b"
grep -x "TAGS=foo:foo=b" /etc/machine-info >/dev/null
hostnamectl tags alpha:beta:quux
# A '*' suffix on a tag to remove removes all tags with that prefix, before tags are added.
hostnamectl tags company.x:company.bar=old:companyfoo:other
hostnamectl tags -- '-company.*' +company.foo:company.bar=waldo
assert_eq "$(hostnamectl tags)" "company.bar=waldo:company.foo:companyfoo:other"
hostnamectl tags -- '-company.*:other' -companyfoo +new
assert_eq "$(hostnamectl tags)" "new"
hostnamectl tags new:k=1:kx=2:kk:k
hostnamectl tags -- '-k=*'
assert_eq "$(hostnamectl tags)" "k:kk:kx=2:new"
# The '*' suffix is only allowed for removal
(! hostnamectl tags -- '+foo*')
(! hostnamectl tags -- 'foo*')
assert_eq "$(hostnamectl tags)" "k:kk:kx=2:new"
# Plain and prefixed arguments may not be mixed.
(! hostnamectl tags foo +bar)