]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Merge pull request #30884 from poettering/logind-background-light
authorLennart Poettering <lennart@poettering.net>
Thu, 11 Jan 2024 20:20:01 +0000 (21:20 +0100)
committerGitHub <noreply@github.com>
Thu, 11 Jan 2024 20:20:01 +0000 (21:20 +0100)
logind: add "background-light" + "manager" session classes

man/standard-options.xml
man/systemd-id128.xml
shell-completion/bash/systemd-id128
src/id128/id128.c
test/test-functions
test/units/testsuite-74.id128.sh

index aec9a0d75091e457caa4f9051ce67d08817dc69b..28131348286b119daf26f39693a89c90d5c1b334 100644 (file)
     off JSON output, the default).</para></listitem>
   </varlistentry>
 
+  <varlistentry id='j'>
+    <term><option>-j</option></term>
+
+    <listitem><para>Equivalent to <option>--json=pretty</option> if running on a terminal, and
+    <option>--json=short</option> otherwise.</para></listitem>
+  </varlistentry>
+
   <varlistentry id='signal'>
     <term><option>-s</option></term>
     <term><option>--signal=</option></term>
index b1e6e245865eee8a530e086dfe090a34924df89d..e23532d65d883b0d3b5969000de13729930d590e 100644 (file)
         <xi:include href="version-info.xml" xpointer="v244"/></listitem>
       </varlistentry>
 
+      <xi:include href="standard-options.xml" xpointer="no-pager" />
+      <xi:include href="standard-options.xml" xpointer="no-legend" />
+      <xi:include href="standard-options.xml" xpointer="json" />
+      <xi:include href="standard-options.xml" xpointer="j" />
       <xi:include href="standard-options.xml" xpointer="help" />
       <xi:include href="standard-options.xml" xpointer="version" />
     </variablelist>
index 1c196391c80dfcbae2f24ca0ed6971566d08e689..74ea1016a9332f2f5778bb79e196f1f7da5eeef3 100644 (file)
@@ -28,12 +28,13 @@ _systemd_id128() {
     local i verb comps
     local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword
     local -A OPTS=(
-        [STANDALONE]='-h --help --version -p --pretty'
-        [ARG]='-a --app-specific'
+        [STANDALONE]='-h --help --version -p --pretty --value -u --uuid --no-legend --no-pager -j'
+        [ARG]='-a --app-specific --json'
     )
 
     local -A VERBS=(
         [STANDALONE]='new machine-id boot-id invocation-id help'
+        [ARG]='show'
     )
 
     _init_completion || return
@@ -43,6 +44,9 @@ _systemd_id128() {
             --app-specific|-a)
                 comps=""
                 ;;
+            --json)
+                comps="short pretty off"
+                ;;
         esac
         COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
         return 0
@@ -65,6 +69,12 @@ _systemd_id128() {
         comps=${VERBS[*]}
     elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
         comps=''
+    elif __contains_word "$verb" ${VERBS[ARG]}; then
+        case $verb in
+            show)
+                comps="$(IFS='\n ' systemd-id128 show --no-legend)"
+                ;;
+        esac
     fi
 
     COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
index d726ab7051c9dfcdc46def2125b3666ad0c6b28d..fa86cf666bf7b6750ba174f85992d6b2aa3eacc9 100644 (file)
@@ -5,18 +5,22 @@
 
 #include "alloc-util.h"
 #include "build.h"
+#include "format-table.h"
 #include "gpt.h"
 #include "id128-print.h"
 #include "main-func.h"
+#include "parse-argument.h"
 #include "pretty-print.h"
 #include "strv.h"
-#include "format-table.h"
 #include "terminal-util.h"
 #include "verbs.h"
 
 static Id128PrettyPrintMode arg_mode = ID128_PRINT_ID128;
 static sd_id128_t arg_app = {};
 static bool arg_value = false;
+static PagerFlags arg_pager_flags = 0;
+static bool arg_legend = true;
+static JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF;
 
 static int verb_new(int argc, char **argv, void *userdata) {
         return id128_print_new(arg_mode);
@@ -150,9 +154,9 @@ static int verb_show(int argc, char **argv, void *userdata) {
                 }
 
         if (table) {
-                r = table_print(table, NULL);
+                r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend);
                 if (r < 0)
-                        return table_log_print_error(r);
+                        return r;
         }
 
         return 0;
@@ -177,6 +181,12 @@ static int help(void) {
                "  help                    Show this help\n"
                "\nOptions:\n"
                "  -h --help               Show this help\n"
+               "     --no-pager           Do not pipe output into a pager\n"
+               "     --no-legend          Do not show the headers and footers\n"
+               "     --json=FORMAT        Output inspection data in JSON (takes one of\n"
+               "                          pretty, short, off)\n"
+               "  -j                      Equivalent to --json=pretty (on TTY) or\n"
+               "                          --json=short (otherwise)\n"
                "  -p --pretty             Generate samples of program code\n"
                "  -P --value              Only print the value\n"
                "  -a --app-specific=ID    Generate app-specific IDs\n"
@@ -197,11 +207,17 @@ static int verb_help(int argc, char **argv, void *userdata) {
 static int parse_argv(int argc, char *argv[]) {
         enum {
                 ARG_VERSION = 0x100,
+                ARG_NO_PAGER,
+                ARG_NO_LEGEND,
+                ARG_JSON,
         };
 
         static const struct option options[] = {
                 { "help",         no_argument,       NULL, 'h'              },
                 { "version",      no_argument,       NULL, ARG_VERSION      },
+                { "no-pager",     no_argument,       NULL, ARG_NO_PAGER     },
+                { "no-legend",    no_argument,       NULL, ARG_NO_LEGEND    },
+                { "json",         required_argument, NULL, ARG_JSON         },
                 { "pretty",       no_argument,       NULL, 'p'              },
                 { "value",        no_argument,       NULL, 'P'              },
                 { "app-specific", required_argument, NULL, 'a'              },
@@ -214,7 +230,7 @@ static int parse_argv(int argc, char *argv[]) {
         assert(argc >= 0);
         assert(argv);
 
-        while ((c = getopt_long(argc, argv, "hpa:uP", options, NULL)) >= 0)
+        while ((c = getopt_long(argc, argv, "hpa:uPj", options, NULL)) >= 0)
                 switch (c) {
 
                 case 'h':
@@ -223,6 +239,24 @@ static int parse_argv(int argc, char *argv[]) {
                 case ARG_VERSION:
                         return version();
 
+                case ARG_NO_PAGER:
+                        arg_pager_flags |= PAGER_DISABLE;
+                        break;
+
+                case ARG_NO_LEGEND:
+                        arg_legend = false;
+                        break;
+
+                case 'j':
+                        arg_json_format_flags = JSON_FORMAT_PRETTY_AUTO|JSON_FORMAT_COLOR_AUTO;
+                        break;
+
+                case ARG_JSON:
+                        r = parse_json_argument(optarg, &arg_json_format_flags);
+                        if (r <= 0)
+                                return r;
+
+                        break;
                 case 'p':
                         arg_mode = ID128_PRINT_PRETTY;
                         arg_value = false;
index 6db79bd416123361c3b4b82cd4e45399eab025ef..1ee41b636d3b75a0f928ff30fdad483ae139fa69 100644 (file)
@@ -1653,7 +1653,7 @@ create_empty_image() {
     sfdisk "$LOOPDEV" <<EOF
 label: gpt
 type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B name=esp  size=${esp_size}M
-type=0FC63DAF-8483-4772-8E79-3D69D8477DE4 name=root size=${root_size}M bootable
+type=$(systemd-id128 show root -Pu) name=root size=${root_size}M bootable
 type=BC13C2FF-59E6-4262-A352-B275FD6F7172 name=boot size=${boot_size}M
 type=0FC63DAF-8483-4772-8E79-3D69D8477DE4 name=data
 EOF
index c1b80d660e85e33df7b5d9ea2077b230f7162bf2..f91cd5f78d63eee7de3b3cf9043a844426305aed 100755 (executable)
@@ -22,6 +22,13 @@ systemd-id128 show root-x86-64 --app-specific=4f68bce3e8cd4db196e7fbcaf984b709
 systemd-id128 show --pretty root-x86-64 --app-specific=4f68bce3e8cd4db196e7fbcaf984b709
 [[ "$(systemd-id128 show root-x86-64 --app-specific=4f68bce3e8cd4db196e7fbcaf984b709 -P)" = "8ee5535e7cb14c249e1d28b8dfbb939c" ]]
 
+systemd-id128 show -j
+systemd-id128 show --no-pager
+systemd-id128 show --json=short
+systemd-id128 show --no-legend
+systemd-id128 show --no-pager --no-legend
+systemd-id128 show root -P -u
+
 [[ "$(systemd-id128 new | wc -c)" -eq 33 ]]
 systemd-id128 new -p
 systemd-id128 new -u