]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: add --raw command line option
authorKarel Zak <kzak@redhat.com>
Mon, 9 Dec 2024 11:20:55 +0000 (12:20 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 9 Dec 2024 11:20:55 +0000 (12:20 +0100)
In certain situations, data alignment is not desired.

Addresses: https://github.com/util-linux/util-linux/pull/3255
Signed-off-by: Karel Zak <kzak@redhat.com>
bash-completion/lscpu
sys-utils/lscpu.1.adoc
sys-utils/lscpu.c
sys-utils/lscpu.h

index d79c4c9a65453c4c7bba8af8685e8daec441c1cd..fc55a1922c7b7cc9582d0e15f0f57f6b9bada8dd 100644 (file)
@@ -40,6 +40,7 @@ _lscpu_module()
                                --hex
                                --physical
                                --output-all
+                               --raw
                                --help
                                --version"
                        COMPREPLY=( $(compgen -W "${OPTS_ALL[*]}" -- $cur) )
index 26c078bcdb1c343ba70399e5258bf99e2d540d09..60c769c0450285f6d9dd6d262035c5308e5e837d 100644 (file)
@@ -78,6 +78,9 @@ When specifying the _list_ argument, the string of option, equal sign (=), and _
 +
 The default list of columns may be extended if list is specified in the format +list (e.g., lscpu -p=+MHZ).
 
+*-r*, *--raw*::
+Produce output in its raw format. This option is only applicable for the *--extended*, *--parse*, and *--caches* outputs.
+
 *-s*, *--sysroot* _directory_::
 Gather CPU data for a Linux instance other than the instance from which the *lscpu* command is issued. The specified _directory_ is the system root of the Linux instance to be inspected.
 
index 17eaea9f42070a1f2c19dd2cc74bf5b17a3a743b..21c5a99cfb636e04f869436ffbbbe03a8c2acd0a 100644 (file)
@@ -598,6 +598,8 @@ static void print_caches_readable(struct lscpu_cxt *cxt, int cols[], size_t ncol
                scols_table_enable_json(tb, 1);
                scols_table_set_name(tb, "caches");
        }
+       if (cxt->raw)
+               scols_table_enable_raw(tb, 1);
 
        for (i = 0; i < ncols; i++) {
                struct lscpu_coldesc *cd = &coldescs_cache[cols[i]];
@@ -753,6 +755,8 @@ static void print_cpus_readable(struct lscpu_cxt *cxt, int cols[], size_t ncols)
                scols_table_enable_json(tb, 1);
                scols_table_set_name(tb, "cpus");
        }
+       if (cxt->raw)
+               scols_table_enable_raw(tb, 1);
 
        for (i = 0; i < ncols; i++) {
                data = get_cell_header(cxt, cols[i], buf, sizeof(buf));
@@ -1183,6 +1187,7 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_(" -J, --json              use JSON for default or extended format\n"), out);
        fputs(_(" -e, --extended[=<list>] print out an extended readable format\n"), out);
        fputs(_(" -p, --parse[=<list>]    print out a parsable format\n"), out);
+       fputs(_(" -r, --raw               use raw output format (for -e, -p and -C)\n"), out);
        fputs(_(" -s, --sysroot <dir>     use specified directory as system root\n"), out);
        fputs(_(" -x, --hex               print hexadecimal masks rather than lists of CPUs\n"), out);
        fputs(_(" -y, --physical          print physical instead of logical IDs\n"), out);
@@ -1226,6 +1231,7 @@ int main(int argc, char *argv[])
                { "extended",   optional_argument, NULL, 'e' },
                { "json",       no_argument,       NULL, 'J' },
                { "parse",      optional_argument, NULL, 'p' },
+               { "raw",        no_argument,       NULL, 'r' },
                { "sysroot",    required_argument, NULL, 's' },
                { "physical",   no_argument,       NULL, 'y' },
                { "hex",        no_argument,       NULL, 'x' },
@@ -1249,7 +1255,7 @@ int main(int argc, char *argv[])
 
        cxt = lscpu_new_context();
 
-       while ((c = getopt_long(argc, argv, "aBbC::ce::hJp::s:xyV", longopts, NULL)) != -1) {
+       while ((c = getopt_long(argc, argv, "aBbC::ce::hJp::rs:xyV", longopts, NULL)) != -1) {
 
                err_exclusive_options(c, longopts, excl, excl_st);
 
@@ -1289,6 +1295,9 @@ int main(int argc, char *argv[])
                        }
                        cxt->mode = c == 'p' ? LSCPU_OUTPUT_PARSABLE : LSCPU_OUTPUT_READABLE;
                        break;
+               case 'r':
+                       cxt->raw = 1;
+                       break;
                case 's':
                        cxt->prefix = optarg;
                        cxt->noalive = 1;
index 4d394a81d6e87fc760e9c2b80adc4df679660d16..062c55c8abd4b54694d05b53aaf8db90ab2cf73f 100644 (file)
@@ -260,6 +260,7 @@ struct lscpu_cxt {
                     show_compatible : 1,
                     hex : 1,
                     json : 1,
+                    raw : 1,
                     bytes : 1;
 
        int is_cluster; /* For aarch64 if the machine doesn't have ACPI PPTT */