cli: print full version name
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 21 Jan 2020 15:52:12 +0000 (10:52 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 21 Jan 2020 20:14:32 +0000 (15:14 -0500)
Include the release's name and name description, the Git revision
description, and extra information.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I478da57eb24b6a8d0f9c7a0b7b1fb8a41d8e4867
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2839
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
src/cli/babeltrace2-cfg-cli-args.c

index 73d67d7785d50f42ff89788d28dd4a10a5a07dd5..e4bd143054a591a2271cb2388ef5cb4c328cd268 100644 (file)
@@ -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);
+               }
        }
 }
 
This page took 0.027238 seconds and 4 git commands to generate.