text: mask some internal fields
[babeltrace.git] / converter / babeltrace-cfg.c
index 6e07a43749822a3d705360e6f3e5a3aceea5a5b8..7c6883163d030f7d470162d1fb76afc633ceb328 100644 (file)
@@ -130,6 +130,7 @@ struct text_legacy_opts {
        bool clock_date;
        bool clock_gmt;
        bool dbg_info_full_path;
+       bool verbose;
 };
 
 /* Legacy input format format */
@@ -143,7 +144,6 @@ enum legacy_input_format {
 enum legacy_output_format {
        LEGACY_OUTPUT_FORMAT_NONE = 0,
        LEGACY_OUTPUT_FORMAT_TEXT,
-       LEGACY_OUTPUT_FORMAT_CTF_METADATA,
        LEGACY_OUTPUT_FORMAT_DUMMY,
 };
 
@@ -187,7 +187,7 @@ bool text_legacy_opts_is_any_set(struct text_legacy_opts *opts)
                bt_value_array_size(opts->names) > 0 ||
                bt_value_array_size(opts->fields) > 0 ||
                opts->no_delta || opts->clock_cycles || opts->clock_seconds ||
-               opts->clock_date || opts->clock_gmt ||
+               opts->clock_date || opts->clock_gmt || opts->verbose ||
                opts->dbg_info_full_path;
 }
 
@@ -1326,6 +1326,12 @@ struct bt_value *params_from_text_legacy_opts(
                goto error;
        }
 
+       if (bt_value_map_insert_bool(params, "verbose",
+                       text_legacy_opts->verbose)) {
+               print_err_oom();
+               goto error;
+       }
+
        if (insert_flat_names_fields_from_array(params,
                        text_legacy_opts->names, "name")) {
                goto error;
@@ -1361,10 +1367,6 @@ int append_sinks_from_legacy_opts(GPtrArray *sinks,
                plugin_name = "text";
                component_name = "text";
                break;
-       case LEGACY_OUTPUT_FORMAT_CTF_METADATA:
-               plugin_name = "ctf";
-               component_name = "metadata-text";
-               break;
        case LEGACY_OUTPUT_FORMAT_DUMMY:
                plugin_name = "utils";
                component_name = "dummy";
@@ -1700,9 +1702,6 @@ void print_output_legacy_to_sinks(
        case LEGACY_OUTPUT_FORMAT_TEXT:
                output_format = "text";
                break;
-       case LEGACY_OUTPUT_FORMAT_CTF_METADATA:
-               output_format = "ctf-metadata";
-               break;
        case LEGACY_OUTPUT_FORMAT_DUMMY:
                output_format = "dummy";
                break;
@@ -1720,9 +1719,6 @@ void print_output_legacy_to_sinks(
        case LEGACY_OUTPUT_FORMAT_TEXT:
                g_string_append(str, "text.text");
                break;
-       case LEGACY_OUTPUT_FORMAT_CTF_METADATA:
-               g_string_append(str, "ctf.metadata-text");
-               break;
        case LEGACY_OUTPUT_FORMAT_DUMMY:
                g_string_append(str, "utils.dummy");
                break;
@@ -1766,6 +1762,8 @@ void print_output_legacy_to_sinks(
                        text_legacy_opts->clock_date);
                g_string_append_bool_param(str, "clock-gmt",
                        text_legacy_opts->clock_gmt);
+               g_string_append_bool_param(str, "verbose",
+                       text_legacy_opts->verbose);
                ret = append_prefixed_flag_params(str, text_legacy_opts->names,
                        "name");
                if (ret) {
@@ -1896,7 +1894,8 @@ bool validate_cfg(struct bt_config *cfg,
        bool legacy_output = false;
 
        /* Determine if the input and output should be legacy-style */
-       if (*legacy_input_format != LEGACY_INPUT_FORMAT_NONE ||
+       if (cfg->cmd_data.convert.print_ctf_metadata ||
+                       *legacy_input_format != LEGACY_INPUT_FORMAT_NONE ||
                        !bt_value_array_is_empty(legacy_input_paths) ||
                        ctf_legacy_opts_is_any_set(ctf_legacy_opts)) {
                legacy_input = true;
@@ -1930,13 +1929,45 @@ bool validate_cfg(struct bt_config *cfg,
 
                /* Make sure no non-legacy sources are specified */
                if (cfg->cmd_data.convert.sources->len != 0) {
-                       print_input_legacy_to_sources(*legacy_input_format,
-                               legacy_input_paths, ctf_legacy_opts);
+                       if (cfg->cmd_data.convert.print_ctf_metadata) {
+                               printf_err("You cannot instantiate a source component with the `ctf-metadata` output format\n");
+                       } else {
+                               print_input_legacy_to_sources(
+                                       *legacy_input_format,
+                                       legacy_input_paths, ctf_legacy_opts);
+                       }
+
                        goto error;
                }
        }
 
-       if (legacy_output) {
+       /*
+        * Strict rule: if we need to print the CTF metadata, the input
+        * format must be legacy and CTF. Also there should be no
+        * other sinks, and no legacy output format.
+        */
+       if (cfg->cmd_data.convert.print_ctf_metadata) {
+               if (*legacy_input_format != LEGACY_INPUT_FORMAT_CTF) {
+                       printf_err("The `ctf-metadata` output format requires legacy `ctf` input format\n");
+                       goto error;
+               }
+
+               if (bt_value_array_size(legacy_input_paths) != 1) {
+                       printf_err("You need to specify exactly one path with the `ctf-metadata` output format\n");
+                       goto error;
+               }
+
+               if (legacy_output) {
+                       printf_err("You cannot use another legacy output format with the `ctf-metadata` output format\n");
+                       goto error;
+               }
+
+               if (cfg->cmd_data.convert.sinks->len != 0) {
+                       printf_err("You cannot instantiate a sink component with the `ctf-metadata` output format\n");
+                       goto error;
+                       goto error;
+               }
+       } else if (legacy_output) {
                /*
                 * If no legacy output format was specified, default to
                 * "text".
@@ -1964,16 +1995,6 @@ bool validate_cfg(struct bt_config *cfg,
                }
        }
 
-       /*
-        * If the output is the legacy "ctf-metadata" format, then the
-        * input should be the legacy "ctf" input format.
-        */
-       if (*legacy_output_format == LEGACY_OUTPUT_FORMAT_CTF_METADATA &&
-                       *legacy_input_format != LEGACY_INPUT_FORMAT_CTF) {
-               printf_err("Legacy `ctf-metadata` output format requires using legacy `ctf` input format\n");
-               goto error;
-       }
-
        return true;
 
 error:
@@ -3460,14 +3481,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                                                LEGACY_OUTPUT_FORMAT_DUMMY;
                                        break;
                                } else if (!strcmp(arg, "ctf-metadata")) {
-                                       /* Legacy CTF-metadata output format */
-                                       if (legacy_output_format) {
-                                               print_err_dup_legacy_output();
-                                               goto error;
-                                       }
-
-                                       legacy_output_format =
-                                               LEGACY_OUTPUT_FORMAT_CTF_METADATA;
+                                       cfg->cmd_data.convert.print_ctf_metadata = true;
                                        break;
                                }
                        }
@@ -3749,6 +3763,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                        BT_PUT(cfg);
                        goto end;
                case OPT_VERBOSE:
+                       text_legacy_opts.verbose = true;
                        cfg->verbose = true;
                        break;
                case OPT_DEBUG:
@@ -3835,12 +3850,21 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                } else {
                        if (implicit_source_comp
                                        && !bt_value_map_is_empty(implicit_source_comp->params)) {
-                               printf_err("Arguments specified for implicit source, but an explicit source has been specified, overriding it\n");
+                               printf_err("Arguments specified for implicit input format, but an explicit source component instance has been specified: overriding it\n");
                                goto error;
                        }
                }
        }
 
+       /*
+        * At this point if we need to print the CTF metadata text, we
+        * don't care about the legacy/implicit sinks and component
+        * connections.
+        */
+       if (cfg->cmd_data.convert.print_ctf_metadata) {
+               goto end;
+       }
+
        /*
         * If there's a legacy output format, convert it to sink
         * component configurations.
This page took 0.029839 seconds and 4 git commands to generate.