From 842193c9701fb1ab4133d126f6b23937cdcc383b Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Tue, 21 Jan 2020 10:52:12 -0500 Subject: [PATCH] cli: print full version name Include the release's name and name description, the Git revision description, and extra information. Signed-off-by: Philippe Proulx Change-Id: I478da57eb24b6a8d0f9c7a0b7b1fb8a41d8e4867 Reviewed-on: https://review.lttng.org/c/babeltrace/+/2839 Reviewed-by: Francis Deslauriers Tested-by: jenkins --- src/cli/babeltrace2-cfg-cli-args.c | 71 ++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 4 deletions(-) diff --git a/src/cli/babeltrace2-cfg-cli-args.c b/src/cli/babeltrace2-cfg-cli-args.c index 73d67d77..e4bd1430 100644 --- a/src/cli/babeltrace2-cfg-cli-args.c +++ b/src/cli/babeltrace2-cfg-cli-args.c @@ -191,16 +191,79 @@ end: return; } +static +void print_and_indent(const char *str) +{ + const char *ch = &str[0]; + + for (; *ch != '\0'; ch++) { + if (*ch == '\n') { + if (ch[1] != '\0') { + printf("\n "); + } + } else { + printf("%c", *ch); + } + } + + printf("\n"); +} + /* * Prints the Babeltrace version. */ static void print_version(void) { - if (BT_VERSION_GIT[0] == '\0') { - puts("Babeltrace " VERSION); - } else { - puts("Babeltrace " VERSION " - " BT_VERSION_GIT); + bool has_extra_name = strlen(BT_VERSION_EXTRA_NAME) > 0; + bool has_extra_description = strlen(BT_VERSION_EXTRA_DESCRIPTION) > 0; + bool has_extra_patch_names = strlen(BT_VERSION_EXTRA_PATCHES) > 0; + bool has_extra = has_extra_name || has_extra_description || + has_extra_patch_names; + + printf("Babeltrace " VERSION); + + if (strlen(BT_VERSION_NAME) > 0) { + printf(" \"%s\"", BT_VERSION_NAME); + } + + if (strlen(BT_VERSION_GIT) > 0) { + printf(" [%s]", BT_VERSION_GIT); + } + + printf("\n"); + + if (strlen(BT_VERSION_DESCRIPTION) > 0) { + unsigned int columns; + GString *descr; + + if (bt_common_get_term_size(&columns, NULL) < 0) { + /* Width not found: default to 80 */ + columns = 80; + } + + descr = bt_common_fold(BT_VERSION_DESCRIPTION, columns, 0); + BT_ASSERT(descr); + printf("\n%s\n", descr->str); + g_string_free(descr, TRUE); + } + + if (has_extra) { + printf("\n"); + + if (has_extra_name) { + printf("Extra name: %s\n", BT_VERSION_EXTRA_NAME); + } + + if (has_extra_description) { + printf("Extra description:\n "); + print_and_indent(BT_VERSION_EXTRA_DESCRIPTION); + } + + if (has_extra_patch_names) { + printf("Extra patch names:\n "); + print_and_indent(BT_VERSION_EXTRA_PATCHES); + } } } -- 2.34.1