rename `babeltrace.trace-info` to `babeltrace.trace-infos`, `streams` to `stream...
[babeltrace.git] / src / cli / babeltrace2-cfg-cli-args.c
index cb900f48b22e47248694593d9f82fb4191e7ac3a..e7ee709a91f2b1504f7e0133870aff6905843121 100644 (file)
 #include "babeltrace2-cfg-cli-args.h"
 #include "babeltrace2-cfg-cli-args-connect.h"
 #include "babeltrace2-cfg-cli-params-arg.h"
+#include "babeltrace2-log-level.h"
 #include "babeltrace2-plugins.h"
 #include "babeltrace2-query.h"
 #include "autodisc/autodisc.h"
 #include "common/version.h"
 
-static const int cli_default_log_level = BT_LOG_WARNING;
-
 /* INI-style parsing FSM states */
 enum ini_parsing_fsm_state {
        /* Expect a map key (identifier) */
@@ -1301,6 +1300,8 @@ void print_expected_params_format(FILE *fp)
        fprintf(fp, "* Double-quoted string (accepts escape characters).\n");
        fprintf(fp, "* Array, formatted as an opening `[`, a list of comma-separated values\n");
        fprintf(fp, "  (as described by the current list) and a closing `]`.\n");
+       fprintf(fp, "* Map, formatted as an opening `{`, a comma-separated list of PARAM=VALUE\n");
+       fprintf(fp, "  assignments and a closing `}`.\n");
        fprintf(fp, "\n");
        fprintf(fp, "You can put whitespaces allowed around individual `=` and `,` symbols.\n");
        fprintf(fp, "\n");
@@ -1723,7 +1724,7 @@ void print_run_usage(FILE *fp)
        fprintf(fp, "  -x, --connect=CONNECTION          Connect two created components (see the\n");
        fprintf(fp, "                                    expected format of CONNECTION below)\n");
        fprintf(fp, "  -l, --log-level=LVL               Set the log level of the current component to LVL\n");
-       fprintf(fp, "                                    (`N`, `V`, `D`, `I`, `W`, `E`, or `F`)\n");
+       fprintf(fp, "                                    (`N`, `T`, `D`, `I`, `W`, `E`, or `F`)\n");
        fprintf(fp, "  -p, --params=PARAMS               Add initialization parameters PARAMS to the\n");
        fprintf(fp, "                                    current component (see the expected format\n");
        fprintf(fp, "                                    of PARAMS below)\n");
@@ -2127,7 +2128,7 @@ void print_convert_usage(FILE *fp)
        fprintf(fp, "                                    conversion graph, and optionally name it\n");
        fprintf(fp, "                                    NAME\n");
        fprintf(fp, "  -l, --log-level=LVL               Set the log level of the current component to LVL\n");
-       fprintf(fp, "                                    (`N`, `V`, `D`, `I`, `W`, `E`, or `F`)\n");
+       fprintf(fp, "                                    (`N`, `T`, `D`, `I`, `W`, `E`, or `F`)\n");
        fprintf(fp, "  -p, --params=PARAMS               Add initialization parameters PARAMS to the\n");
        fprintf(fp, "                                    current component (see the expected format\n");
        fprintf(fp, "                                    of PARAMS below)\n");
@@ -3135,7 +3136,7 @@ enum convert_current_item_type {
 static
 struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                int *retcode, const bt_value *plugin_paths,
-               int *default_log_level)
+               int *default_log_level, const bt_interrupter *interrupter)
 {
        enum convert_current_item_type current_item_type =
                CONVERT_CURRENT_ITEM_TYPE_NONE;
@@ -3173,6 +3174,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
        struct bt_argpar_parse_ret argpar_parse_ret = { 0 };
        GString *name_gstr = NULL;
        GString *component_arg_for_run = NULL;
+       bt_value *live_inputs_array_val = NULL;
 
        /*
         * Array of `struct implicit_component_args *` created for the sources
@@ -3440,10 +3442,16 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                                         * it in `non_opt_params`.
                                         */
                                        bt_value *array;
+                                       bt_value_array_append_element_status append_element_status;
                                        uint64_t idx = bt_value_array_get_length(non_opt_params) - 1;
 
                                        array = bt_value_array_borrow_element_by_index(non_opt_params, idx);
-                                       bt_value_array_append_string_element(array, arg);
+
+                                       append_element_status = bt_value_array_append_string_element(array, arg);
+                                       if (append_element_status != BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK) {
+                                               BT_CLI_LOGE_APPEND_CAUSE_OOM();
+                                               goto error;
+                                       }
                                } else {
                                        BT_CLI_LOGE_APPEND_CAUSE(
                                                "No current component (--component option) or non-option argument of which to set parameters:\n    %s",
@@ -3841,24 +3849,25 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                case OPT_STREAM_INTERSECTION:
                        /*
                         * Applies to all traces implementing the
-                        * babeltrace.trace-info query.
+                        * babeltrace.trace-infos query.
                         */
                        stream_intersection_mode = true;
                        break;
                case OPT_VERBOSE:
-                       if (*default_log_level != BT_LOG_TRACE &&
-                                       *default_log_level != BT_LOG_DEBUG) {
-                               *default_log_level = BT_LOG_INFO;
-                       }
+                       *default_log_level =
+                               logging_level_min(*default_log_level, BT_LOG_INFO);
                        break;
                case OPT_DEBUG:
-                       *default_log_level = BT_LOG_TRACE;
+                       *default_log_level =
+                               logging_level_min(*default_log_level, BT_LOG_TRACE);
                        break;
                default:
                        break;
                }
        }
 
+       set_auto_log_levels(default_log_level);
+
        /*
         * Legacy behaviour: --verbose used to make the `text` output
         * format print more information. --verbose is now equivalent to
@@ -3996,9 +4005,22 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                                goto end;
                        }
 
-                       ret = append_implicit_component_extra_param(
-                               &implicit_lttng_live_args, "url",
-                               bt_value_string_get(bt_val_non_opt));
+                       live_inputs_array_val = bt_value_array_create();
+                       if (!live_inputs_array_val) {
+                               BT_CLI_LOGE_APPEND_CAUSE_OOM();
+                               goto error;
+                       }
+
+                       if (bt_value_array_append_string_element(
+                                       live_inputs_array_val,
+                                       bt_value_string_get(bt_val_non_opt))) {
+                               BT_CLI_LOGE_APPEND_CAUSE_OOM();
+                               goto error;
+                       }
+
+                       ret = append_parameter_to_args(
+                               implicit_lttng_live_args.extra_params,
+                               "inputs", live_inputs_array_val);
                        if (ret) {
                                goto error;
                        }
@@ -4031,10 +4053,13 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
 
                        status = auto_discover_source_components(non_opts, plugins, plugin_count,
                                auto_source_discovery_restrict_component_class_name,
-                               *default_log_level >= 0 ? *default_log_level : cli_default_log_level,
-                               &auto_disc);
+                               *default_log_level, &auto_disc, interrupter);
 
                        if (status != 0) {
+                               if (status == AUTO_SOURCE_DISCOVERY_STATUS_INTERRUPTED) {
+                                       BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN(
+                                               "Babeltrace CLI", "Automatic source discovery interrupted by the user");
+                               }
                                goto error;
                        }
 
@@ -4312,14 +4337,6 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                goto end;
        }
 
-       /*
-        * If the log level is still unset at this point, set it to
-        * the program's default.
-        */
-       if (*default_log_level < 0) {
-               *default_log_level = cli_default_log_level;
-       }
-
        cfg = bt_config_run_from_args_array(run_args, retcode,
                plugin_paths, *default_log_level);
        if (!cfg) {
@@ -4334,14 +4351,6 @@ error:
        BT_OBJECT_PUT_REF_AND_RESET(cfg);
 
 end:
-       /*
-        * If the log level is still unset at this point, set it to
-        * the program's default.
-        */
-       if (*default_log_level < 0) {
-               *default_log_level = cli_default_log_level;
-       }
-
        bt_argpar_parse_ret_fini(&argpar_parse_ret);
 
        free(output);
@@ -4354,6 +4363,7 @@ end:
                g_string_free(name_gstr, TRUE);
        }
 
+       bt_value_put_ref(live_inputs_array_val);
        bt_value_put_ref(run_args);
        bt_value_put_ref(all_names);
        destroy_glist_of_gstring(source_names);
@@ -4396,9 +4406,9 @@ void print_gen_usage(FILE *fp)
        fprintf(fp, "\n");
        fprintf(fp, "General options:\n");
        fprintf(fp, "\n");
-       fprintf(fp, "  -d, --debug                       Enable debug mode (same as --log-level=V)\n");
+       fprintf(fp, "  -d, --debug                       Enable debug mode (same as --log-level=T)\n");
        fprintf(fp, "  -h, --help                        Show this help and quit\n");
-       fprintf(fp, "  -l, --log-level=LVL               Set the default log level to LVL (`N`, `V`, `D`,\n");
+       fprintf(fp, "  -l, --log-level=LVL               Set the default log level to LVL (`N`, `T`, `D`,\n");
        fprintf(fp, "                                    `I`, `W` (default), `E`, or `F`)\n");
        fprintf(fp, "      --omit-home-plugin-path       Omit home plugins from plugin search path\n");
        fprintf(fp, "                                    (~/.local/lib/babeltrace2/plugins)\n");
@@ -4422,7 +4432,8 @@ void print_gen_usage(FILE *fp)
 struct bt_config *bt_config_cli_args_create(int argc, const char *argv[],
                int *retcode, bool omit_system_plugin_path,
                bool omit_home_plugin_path,
-               const bt_value *initial_plugin_paths)
+               const bt_value *initial_plugin_paths,
+               const bt_interrupter *interrupter)
 {
        struct bt_config *config = NULL;
        int i;
@@ -4514,28 +4525,28 @@ struct bt_config *bt_config_cli_args_create(int argc, const char *argv[],
 
                        switch (item_opt->descr->id) {
                                case OPT_DEBUG:
-                                       default_log_level = BT_LOG_TRACE;
+                                       default_log_level =
+                                               logging_level_min(default_log_level, BT_LOG_TRACE);
                                        break;
                                case OPT_VERBOSE:
-                                       /*
-                                        * Legacy: do not override a previous
-                                        * --debug because --verbose and --debug
-                                        * can be specified together (in this
-                                        * case we want the lowest log level to
-                                        * apply, TRACE).
-                                        */
-                                       default_log_level = BT_LOG_INFO;
+                                       default_log_level =
+                                               logging_level_min(default_log_level, BT_LOG_INFO);
                                        break;
                                case OPT_LOG_LEVEL:
-                                       default_log_level =
-                                               bt_log_get_level_from_string(item_opt->arg);
-                                       if (default_log_level < 0) {
+                               {
+                                       int level = bt_log_get_level_from_string(item_opt->arg);
+
+                                       if (level < 0) {
                                                BT_CLI_LOGE_APPEND_CAUSE(
                                                        "Invalid argument for --log-level option:\n    %s",
                                                        item_opt->arg);
                                                goto error;
                                        }
+
+                                       default_log_level =
+                                               logging_level_min(default_log_level, level);
                                        break;
+                               }
                                case OPT_PLUGIN_PATH:
                                        if (bt_config_append_plugin_paths_check_setuid_setgid(
                                                        plugin_paths, item_opt->arg)) {
@@ -4620,13 +4631,16 @@ struct bt_config *bt_config_cli_args_create(int argc, const char *argv[],
        BT_ASSERT(command_argc >= 0);
 
        /*
-        * The convert command can set its own default log level for
-        * backward compatibility reasons. It only does so if there's no
-        * log level yet, so do not force one for this command.
+        * For all commands other than `convert`, we now know the log level to
+        * use, so we can apply it with `set_auto_log_levels`.
+        *
+        * The convert command has `--debug` and `--verbose` arguments that are
+        * equivalent to the top-level arguments of the same name.  So after it
+        * has parsed its arguments, `bt_config_convert_from_args` calls
+        * `set_auto_log_levels` itself.
         */
-       if (command_type != COMMAND_TYPE_CONVERT && default_log_level < 0) {
-               /* Default log level */
-               default_log_level = cli_default_log_level;
+       if (command_type != COMMAND_TYPE_CONVERT) {
+               set_auto_log_levels(&default_log_level);
        }
 
        /*
@@ -4649,7 +4663,7 @@ struct bt_config *bt_config_cli_args_create(int argc, const char *argv[],
                break;
        case COMMAND_TYPE_CONVERT:
                config = bt_config_convert_from_args(command_argc, command_argv,
-                       retcode, plugin_paths, &default_log_level);
+                       retcode, plugin_paths, &default_log_level, interrupter);
                break;
        case COMMAND_TYPE_LIST_PLUGINS:
                config = bt_config_list_plugins_from_args(command_argc,
This page took 0.026749 seconds and 4 git commands to generate.