From: Lennart Poettering Date: Mon, 23 Mar 2026 21:17:05 +0000 (+0100) Subject: Define options and verbs through "magic macros" (#40880) X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e7a176fe461d05a68a3df6bfdcb9c330a3345671;p=thirdparty%2Fsystemd.git Define options and verbs through "magic macros" (#40880) This is an another alternative for #40656, based on @poettering's suggestion to use an ELF section. The output of --help is generated using format-table, but the details of the formatting a bit off: different sections in the table (verbs, option groups) are not aligned to the same column. Our current table formatting doesn't make this easy. If somebody has an idea how to do this without too much pain, please make suggestions. Another thing that I didn't know how to do nicely, was to use the two columns of separation. But maybe this doesn't matter. If we switch to one column everywhere, I don't think people will care. Example output: ```console $ build/systemd-id128 -h | cat systemd-id128 [OPTIONS...] COMMAND Generate and print 128-bit identifiers. Commands: new Generate a new ID machine-id Print the ID of current machine boot-id Print the ID of current boot invocation-id Print the ID of current invocation var-partition-uuid Print the UUID for the /var/ partition show [NAME|UUID] Print one or more UUIDs help Show this help Options: -h --help Show this help --version Show package version --no-pager Do not start a pager --no-legend Do not show headers and footers --json=FORMAT Output inspection data in JSON (takes one of pretty, short, off) -j Equivalent to --json=pretty (on TTY) or --json=short (otherwise) -p --pretty Generate samples of program code -P --value Only print the value -a --app-specific=ID Generate app-specific IDs -u --uuid Output in UUID format See the systemd-id128(1) man page for details. ``` The output wraps automatically with terminal width. If the terminal is extremely narrow, ellipsization occurs. I think this doesn't matter and/or is actually a feature. Such narrow terminals mostly occur in testing, so it doesn't matter what exactly we do, as long as it is something somewhat reasonable. Anyway, I think this is enough as PoC. Please compare this with the previous approach. /cc @behrmann, @YHNdnzj, @poettering The three binaries that are converted have options, verbs, optional arguments, and options terminate option parsing, so most of the functionality is there. One thing that I didn't implement that was present in previous PRs is "namespaces", i.e. multiple parsers in the same source file. I expect that we can handle this similarly to option groups. --- e7a176fe461d05a68a3df6bfdcb9c330a3345671