machinectl: add -P
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 2 Mar 2024 11:25:22 +0000 (12:25 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 4 Mar 2024 12:12:23 +0000 (16:12 +0400)
man/machinectl.xml
man/timedatectl.xml
src/machine/machinectl.c

index 319942207bf94c8f3b7d5cab7c2a85a3f02fd189..3964dc0580b4530cf611781647151dc19a239267 100644 (file)
         <xi:include href="version-info.xml" xpointer="v206"/></listitem>
       </varlistentry>
 
+       <varlistentry>
+        <term><option>--value</option></term>
+
+        <listitem><para>When printing properties with <command>show</command>, only print the value,
+        and skip the property name and <literal>=</literal>.</para>
+
+        <xi:include href="version-info.xml" xpointer="v230"/></listitem>
+      </varlistentry>
+
+      <xi:include href="timedatectl.xml" xpointer="option-P"/>
+
       <varlistentry>
         <term><option>-a</option></term>
         <term><option>--all</option></term>
         <xi:include href="version-info.xml" xpointer="v206"/></listitem>
       </varlistentry>
 
-       <varlistentry>
-        <term><option>--value</option></term>
-
-        <listitem><para>When printing properties with <command>show</command>, only print the value,
-        and skip the property name and <literal>=</literal>.</para>
-
-        <xi:include href="version-info.xml" xpointer="v230"/></listitem>
-      </varlistentry>
-
       <varlistentry>
         <term><option>-l</option></term>
         <term><option>--full</option></term>
index e44a63870a90e22b2e6a712fe3b8ee6e4fcbbc61..ece8833295ea1c5106953db9b55e05d31383d6ad 100644 (file)
         <xi:include href="version-info.xml" xpointer="v239"/></listitem>
       </varlistentry>
 
-      <varlistentry>
+      <varlistentry id='option-P'>
         <term><option>-P</option></term>
 
         <listitem>
index 97dceaaf16bc47870865fdf8e14dc78bd07388fa..bab3719a495b8bc97b94137fe512a237982ce3a6 100644 (file)
@@ -2058,9 +2058,10 @@ static int help(int argc, char *argv[], void *userdata) {
                "  -H --host=[USER@]HOST       Operate on remote host\n"
                "  -M --machine=CONTAINER      Operate on local container\n"
                "  -p --property=NAME          Show only properties by this name\n"
+               "     --value                  When showing properties, only print the value\n"
+               "  -P NAME                     Equivalent to --value --property=NAME\n"
                "  -q --quiet                  Suppress output\n"
                "  -a --all                    Show all properties, including empty ones\n"
-               "     --value                  When showing properties, only print the value\n"
                "  -l --full                   Do not ellipsize output\n"
                "     --kill-whom=WHOM         Whom to send signal to\n"
                "  -s --signal=SIGNAL          Which signal to send\n"
@@ -2115,8 +2116,8 @@ static int parse_argv(int argc, char *argv[]) {
                 { "help",            no_argument,       NULL, 'h'                 },
                 { "version",         no_argument,       NULL, ARG_VERSION         },
                 { "property",        required_argument, NULL, 'p'                 },
-                { "all",             no_argument,       NULL, 'a'                 },
                 { "value",           no_argument,       NULL, ARG_VALUE           },
+                { "all",             no_argument,       NULL, 'a'                 },
                 { "full",            no_argument,       NULL, 'l'                 },
                 { "no-pager",        no_argument,       NULL, ARG_NO_PAGER        },
                 { "no-legend",       no_argument,       NULL, ARG_NO_LEGEND       },
@@ -2152,7 +2153,7 @@ static int parse_argv(int argc, char *argv[]) {
         optind = 0;
 
         for (;;) {
-                static const char option_string[] = "-hp:als:H:M:qn:o:E:V";
+                static const char option_string[] = "-hp:P:als:H:M:qn:o:E:V";
 
                 c = getopt_long(argc, argv, option_string + reorder, options, NULL);
                 if (c < 0)
@@ -2213,14 +2214,20 @@ static int parse_argv(int argc, char *argv[]) {
                         return version();
 
                 case 'p':
+                case 'P':
                         r = strv_extend(&arg_property, optarg);
                         if (r < 0)
                                 return log_oom();
 
-                        /* If the user asked for a particular
-                         * property, show it to them, even if it is
-                         * empty. */
+                        /* If the user asked for a particular property, show it to them, even if empty. */
                         SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_SHOW_EMPTY, true);
+
+                        if (c == 'p')
+                                break;
+                        _fallthrough_;
+
+                case ARG_VALUE:
+                        SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_ONLY_VALUE, true);
                         break;
 
                 case 'a':
@@ -2228,10 +2235,6 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_all = true;
                         break;
 
-                case ARG_VALUE:
-                        SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_ONLY_VALUE, true);
-                        break;
-
                 case 'l':
                         arg_full = true;
                         break;