]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
id128: add option -P to only show value
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 26 Aug 2023 10:12:01 +0000 (12:12 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 29 Aug 2023 14:06:47 +0000 (17:06 +0300)
We have '-P' in systemctl with similar meaning.

Partially closes https://github.com/systemd/systemd/issues/27514.

man/systemd-id128.xml
src/id128/id128.c
test/units/testsuite-74.id128.sh

index 221155045134c04d66d6f5c5dbd3e42f1138fdf8..6cb51fa777fc4931183d0a754c6c53359a19c3a4 100644 (file)
         <xi:include href="version-info.xml" xpointer="v240"/></listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term><option>-P</option></term>
+        <term><option>--value</option></term>
+
+        <listitem><para>Only print the value. May be combined with
+        <option>-u</option>/<option>--uuid</option>.</para></listitem>
+      </varlistentry>
+
       <varlistentry>
         <term><option>-a <replaceable>app-id</replaceable></option></term>
         <term><option>--app-specific=<replaceable>app-id</replaceable></option></term>
index a8c5c9ac6cff70fcc4b6c38990bf878e7e929907..c22376d4fcd3d91adebc44882605599f38129814 100644 (file)
@@ -16,6 +16,7 @@
 
 static Id128PrettyPrintMode arg_mode = ID128_PRINT_ID128;
 static sd_id128_t arg_app = {};
+static bool arg_value = false;
 
 static int verb_new(int argc, char **argv, void *userdata) {
         return id128_print_new(arg_mode);
@@ -85,7 +86,10 @@ static int show_one(Table **table, const char *name, sd_id128_t uuid, bool first
                         puts("");
                 return 0;
 
-        } else {
+        } else if (arg_value)
+                return id128_pretty_print(uuid, arg_mode);
+
+        else {
                 if (!*table) {
                         *table = table_new("name", "id");
                         if (!*table)
@@ -191,6 +195,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "help",         no_argument,       NULL, 'h'              },
                 { "version",      no_argument,       NULL, ARG_VERSION      },
                 { "pretty",       no_argument,       NULL, 'p'              },
+                { "value",        no_argument,       NULL, 'P'              },
                 { "app-specific", required_argument, NULL, 'a'              },
                 { "uuid",         no_argument,       NULL, 'u'              },
                 {},
@@ -201,7 +206,7 @@ static int parse_argv(int argc, char *argv[]) {
         assert(argc >= 0);
         assert(argv);
 
-        while ((c = getopt_long(argc, argv, "hpa:u", options, NULL)) >= 0)
+        while ((c = getopt_long(argc, argv, "hpa:uP", options, NULL)) >= 0)
                 switch (c) {
 
                 case 'h':
@@ -212,6 +217,13 @@ static int parse_argv(int argc, char *argv[]) {
 
                 case 'p':
                         arg_mode = ID128_PRINT_PRETTY;
+                        arg_value = false;
+                        break;
+
+                case 'P':
+                        arg_value = true;
+                        if (arg_mode == ID128_PRINT_PRETTY)
+                                arg_mode = ID128_PRINT_ID128;
                         break;
 
                 case 'a':
index 213333d9d1fe98e931c6e6fbd1d8583ecda56fb5..4e2e1257dc9ec6782bb0d66938bcd57465d8ca04 100755 (executable)
@@ -9,7 +9,8 @@ set -o pipefail
 systemd-id128 --help
 systemd-id128 help
 systemd-id128 show
-systemd-id128 show --pretty | tail -n10
+systemd-id128 show --pretty | tail
+systemd-id128 show --value | tail
 systemd-id128 show 4f68bce3e8cd4db196e7fbcaf984b709 # root-x86-64
 systemd-id128 show --pretty 4f68bce3e8cd4db196e7fbcaf984b709