From: Christian Goeschel Ndjomouo Date: Mon, 23 Mar 2026 02:56:56 +0000 (-0400) Subject: lsmem: add column header annotations X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=951862cc4a2c19a9f6a55243ac0e2af202850012;p=thirdparty%2Futil-linux.git lsmem: add column header annotations Signed-off-by: Christian Goeschel Ndjomouo --- diff --git a/bash-completion/lsmem b/bash-completion/lsmem index 27793e743..484b557a3 100644 --- a/bash-completion/lsmem +++ b/bash-completion/lsmem @@ -5,6 +5,10 @@ _lsmem_module() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" case $prev in + '--annotate') + COMPREPLY=( $(compgen -W "always auto never" -- $cur) ) + return 0 + ;; '-o'|'--output') local prefix realcur OUTPUT_ALL OUTPUT realcur="${cur##*,}" @@ -34,6 +38,7 @@ _lsmem_module() ;; esac OPTS=" + --annotate --json --pairs --all diff --git a/sys-utils/lsmem.1.adoc b/sys-utils/lsmem.1.adoc index 26c330de7..0c051b668 100644 --- a/sys-utils/lsmem.1.adoc +++ b/sys-utils/lsmem.1.adoc @@ -97,6 +97,8 @@ Gather memory data for a Linux instance other than the instance from which the * *--summary*[**=**_when_]:: This option controls summary lines output. The optional argument _when_ can be *never*, *always* or *only*. If the _when_ argument is omitted, it defaults to *only*. The summary output is suppressed for *--raw*, *--pairs*, and *--json*. +include::man-common/annotate.adoc[] + include::man-common/help-version.adoc[] == ENVIRONMENT diff --git a/sys-utils/lsmem.c b/sys-utils/lsmem.c index 68b2d3036..007beaf6e 100644 --- a/sys-utils/lsmem.c +++ b/sys-utils/lsmem.c @@ -95,7 +95,8 @@ struct lsmem { split_by_memmap_on_memory : 1, split_by_config : 1, have_zones : 1, - have_memconfig : 1; + have_memconfig : 1, + annotate_headers : 1; }; @@ -667,20 +668,21 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_("List the ranges of available memory with their online status.\n"), out); fputs(USAGE_OPTIONS, out); - fputs(_(" -J, --json use JSON output format\n"), out); - fputs(_(" -P, --pairs use key=\"value\" output format\n"), out); - fputs(_(" -a, --all list each individual memory block\n"), out); - fputs(_(" -b, --bytes print SIZE in bytes rather than in human readable format\n"), out); - fputs(_(" -n, --noheadings don't print headings\n"), out); - fputs(_(" -o, --output output columns\n"), out); - fputs(_(" --output-all output all columns\n"), out); - fputs(_(" -r, --raw use raw output format\n"), out); - fputs(_(" -S, --split split ranges by specified columns\n"), out); - fputs(_(" -s, --sysroot use the specified directory as system root\n"), out); - fputs(_(" --summary[=when] print summary information (never,always or only)\n"), out); + fputs(_(" -J, --json use JSON output format\n"), out); + fputs(_(" -P, --pairs use key=\"value\" output format\n"), out); + fputs(_(" -a, --all list each individual memory block\n"), out); + fputs(_(" -b, --bytes print SIZE in bytes rather than in human readable format\n"), out); + fputs(_(" -n, --noheadings don't print headings\n"), out); + fputs(_(" -o, --output output columns\n"), out); + fputs(_(" --output-all output all columns\n"), out); + fputs(_(" -r, --raw use raw output format\n"), out); + fputs(_(" --annotate[=] annotate columns with a tooltip (always|never|auto)\n"), out); + fputs(_(" -S, --split split ranges by specified columns\n"), out); + fputs(_(" -s, --sysroot use the specified directory as system root\n"), out); + fputs(_(" --summary[=when] print summary information (never,always or only)\n"), out); fputs(USAGE_SEPARATOR, out); - fprintf(out, USAGE_HELP_OPTIONS(22)); + fprintf(out, USAGE_HELP_OPTIONS(27)); fputs(USAGE_COLUMNS, out); for (i = 0; i < ARRAY_SIZE(coldescs); i++) @@ -698,13 +700,14 @@ int main(int argc, char **argv) .want_summary = 1 }, *lsmem = &_lsmem; - const char *outarg = NULL, *splitarg = NULL, *prefix = NULL; + const char *outarg = NULL, *splitarg = NULL, *prefix = NULL, *annotate_opt_arg = NULL; int c; size_t i; enum { LSMEM_OPT_SUMARRY = CHAR_MAX + 1, - OPT_OUTPUT_ALL + OPT_OUTPUT_ALL, + OPT_ANNOTATE, }; static const struct option longopts[] = { @@ -721,6 +724,7 @@ int main(int argc, char **argv) {"split", required_argument, NULL, 'S'}, {"version", no_argument, NULL, 'V'}, {"summary", optional_argument, NULL, LSMEM_OPT_SUMARRY }, + { "annotate", optional_argument, NULL, OPT_ANNOTATE }, {NULL, 0, NULL, 0} }; static const ul_excl_t excl[] = { /* rows and cols in ASCII order */ @@ -787,7 +791,9 @@ int main(int argc, char **argv) } else lsmem->want_table = 0; break; - + case OPT_ANNOTATE: + annotate_opt_arg = optarg; + break; case 'h': usage(); case 'V': @@ -802,6 +808,9 @@ int main(int argc, char **argv) errtryhelp(EXIT_FAILURE); } + if (annotationwanted(annotate_opt_arg)) + lsmem->annotate_headers = 1; + if (lsmem->want_table + lsmem->want_summary == 0) errx(EXIT_FAILURE, _("options --{raw,json,pairs} and --summary=only are mutually exclusive")); @@ -893,6 +902,9 @@ int main(int argc, char **argv) break; } } + + if (lsmem->annotate_headers && ci->help) + scols_column_refer_annotation(cl, ci->help); } if (splitarg) {