Move to kernel style SPDX license identifiers
[babeltrace.git] / src / cli / babeltrace2-cfg-cli-args.c
index 420e1efc0926ec18a98acfcd08c44caaf2c46ef0..37b29ec0ab197b44f0de24dcbdd90899bacded0b 100644 (file)
@@ -1,25 +1,9 @@
 /*
- * Babeltrace trace converter - parameter parsing
+ * SPDX-License-Identifier: MIT
  *
  * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
  *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
+ * Babeltrace trace converter - parameter parsing
  */
 
 #define BT_LOG_TAG "CLI/CFG-CLI-ARGS"
@@ -191,16 +175,96 @@ 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 (GIT_VERSION[0] == '\0') {
-               puts("Babeltrace " VERSION);
-       } else {
-               puts("Babeltrace " VERSION  " - " GIT_VERSION);
+       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("%sBabeltrace %s%s",
+               bt_common_color_bold(),
+               VERSION,
+               bt_common_color_reset());
+
+       if (strlen(BT_VERSION_NAME) > 0) {
+               printf(" \"%s%s%s%s\"",
+                       bt_common_color_fg_bright_blue(),
+                       bt_common_color_bold(),
+                       BT_VERSION_NAME,
+                       bt_common_color_reset());
+       }
+
+       if (strlen(BT_VERSION_GIT) > 0) {
+               printf(" [%s%s%s]",
+                       bt_common_color_fg_yellow(),
+                       BT_VERSION_GIT,
+                       bt_common_color_reset());
+       }
+
+       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("%sExtra name%s: %s\n",
+                               bt_common_color_fg_cyan(),
+                               bt_common_color_reset(),
+                               BT_VERSION_EXTRA_NAME);
+               }
+
+               if (has_extra_description) {
+                       printf("%sExtra description%s:\n  ",
+                               bt_common_color_fg_cyan(),
+                               bt_common_color_reset());
+                       print_and_indent(BT_VERSION_EXTRA_DESCRIPTION);
+               }
+
+               if (has_extra_patch_names) {
+                       printf("%sExtra patch names%s:\n  ",
+                               bt_common_color_fg_cyan(),
+                               bt_common_color_reset());
+                       print_and_indent(BT_VERSION_EXTRA_PATCHES);
+               }
        }
 }
 
@@ -3563,7 +3627,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                switch (argpar_item_opt->descr->id) {
                case OPT_BEGIN:
                        if (trimmer_has_begin) {
-                               printf("At --begin option: --begin or --timerange option already specified\n    %s\n",
+                               BT_CLI_LOGE_APPEND_CAUSE("At --begin option: --begin or --timerange option already specified\n    %s\n",
                                        arg);
                                goto error;
                        }
@@ -3578,7 +3642,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                        break;
                case OPT_END:
                        if (trimmer_has_end) {
-                               printf("At --end option: --end or --timerange option already specified\n    %s\n",
+                               BT_CLI_LOGE_APPEND_CAUSE("At --end option: --end or --timerange option already specified\n    %s\n",
                                        arg);
                                goto error;
                        }
@@ -3597,7 +3661,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                        char *end;
 
                        if (trimmer_has_begin || trimmer_has_end) {
-                               printf("At --timerange option: --begin, --end, or --timerange option already specified\n    %s\n",
+                               BT_CLI_LOGE_APPEND_CAUSE("At --timerange option: --begin, --end, or --timerange option already specified\n    %s\n",
                                        arg);
                                goto error;
                        }
This page took 0.026022 seconds and 4 git commands to generate.