lib: update and simplify the `bt_object` API
[babeltrace.git] / cli / babeltrace-cfg-cli-args.c
index c157063429482e2dd4070c12699674e41df7a1ab..32e950a7d67317a711eefb3bea93cd9532229b58 100644 (file)
@@ -28,7 +28,7 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
 #include <stdio.h>
 #include <stdbool.h>
 #include <inttypes.h>
@@ -41,6 +41,7 @@
 #include "babeltrace-cfg.h"
 #include "babeltrace-cfg-cli-args.h"
 #include "babeltrace-cfg-cli-args-connect.h"
+#include "version.h"
 
 /*
  * Error printf() macro which prepends "Error: " the first time it's
@@ -607,10 +608,10 @@ void plugin_comp_cls_names(const char *arg, char **name, char **plugin,
        GString *gs_comp_cls = NULL;
        size_t end_pos;
 
-       assert(arg);
-       assert(plugin);
-       assert(comp_cls);
-       assert(comp_cls_type);
+       BT_ASSERT(arg);
+       BT_ASSERT(plugin);
+       BT_ASSERT(comp_cls);
+       BT_ASSERT(comp_cls_type);
 
        if (!bt_common_string_is_printable(arg)) {
                printf_err("Argument contains a non-printable character\n");
@@ -729,7 +730,11 @@ end:
 static
 void print_version(void)
 {
-       puts("Babeltrace " VERSION);
+       if (GIT_VERSION[0] == '\0') {
+               puts("Babeltrace " VERSION);
+       } else {
+               puts("Babeltrace " VERSION  " - " GIT_VERSION);
+       }
 }
 
 /*
@@ -784,7 +789,8 @@ struct bt_config_component *bt_config_component_create(
                goto error;
        }
 
-       bt_object_init(cfg_component, bt_config_component_destroy);
+       bt_object_init_shared(&cfg_component->base,
+               bt_config_component_destroy);
        cfg_component->type = type;
        cfg_component->plugin_name = g_string_new(plugin_name);
        if (!cfg_component->plugin_name) {
@@ -909,6 +915,9 @@ void bt_config_destroy(struct bt_object *obj)
                if (cfg->cmd_data.print_ctf_metadata.path) {
                        g_string_free(cfg->cmd_data.print_ctf_metadata.path,
                                TRUE);
+                       g_string_free(
+                               cfg->cmd_data.print_ctf_metadata.output_path,
+                               TRUE);
                }
                break;
        case BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS:
@@ -916,6 +925,9 @@ void bt_config_destroy(struct bt_object *obj)
                        g_string_free(
                                cfg->cmd_data.print_lttng_live_sessions.url,
                                TRUE);
+                       g_string_free(
+                               cfg->cmd_data.print_lttng_live_sessions.output_path,
+                               TRUE);
                }
                break;
        default:
@@ -1180,9 +1192,9 @@ end:
 static
 void append_param_arg(GString *params_arg, const char *key, const char *value)
 {
-       assert(params_arg);
-       assert(key);
-       assert(value);
+       BT_ASSERT(params_arg);
+       BT_ASSERT(key);
+       BT_ASSERT(value);
 
        if (params_arg->len != 0) {
                g_string_append_c(params_arg, ',');
@@ -1488,7 +1500,7 @@ struct bt_config *bt_config_base_create(enum bt_config_command command,
                goto error;
        }
 
-       bt_object_init(cfg, bt_config_destroy);
+       bt_object_init_shared(&cfg->base, bt_config_destroy);
        cfg->command = command;
        cfg->command_needs_plugins = needs_plugins;
 
@@ -1659,6 +1671,12 @@ struct bt_config *bt_config_print_ctf_metadata_create(
                goto error;
        }
 
+       cfg->cmd_data.print_ctf_metadata.output_path = g_string_new(NULL);
+       if (!cfg->cmd_data.print_ctf_metadata.output_path) {
+               print_err_oom();
+               goto error;
+       }
+
        goto end;
 
 error:
@@ -1687,6 +1705,13 @@ struct bt_config *bt_config_print_lttng_live_sessions_create(
                goto error;
        }
 
+       cfg->cmd_data.print_lttng_live_sessions.output_path =
+               g_string_new(NULL);
+       if (!cfg->cmd_data.print_lttng_live_sessions.output_path) {
+               print_err_oom();
+               goto error;
+       }
+
        goto end;
 
 error:
@@ -2059,7 +2084,7 @@ struct bt_config *bt_config_query_from_args(int argc, const char *argv[],
                        goto error;
                }
 
-               assert(params);
+               BT_ASSERT(params);
                BT_MOVE(cfg->cmd_data.query.cfg_component->params, params);
        } else {
                print_query_usage(stdout);
@@ -2355,7 +2380,7 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[],
        struct bt_value *connection_args = NULL;
        GString *cur_param_key = NULL;
        char error_buf[256] = { 0 };
-       long long retry_duration = -1;
+       long retry_duration = -1;
        struct poptOption run_long_options[] = {
                { "base-params", 'b', POPT_ARG_STRING, NULL, OPT_BASE_PARAMS, NULL, NULL },
                { "component", 'c', POPT_ARG_STRING, NULL, OPT_COMPONENT, NULL, NULL },
@@ -2368,7 +2393,7 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[],
                { "params", 'p', POPT_ARG_STRING, NULL, OPT_PARAMS, NULL, NULL },
                { "plugin-path", '\0', POPT_ARG_STRING, NULL, OPT_PLUGIN_PATH, NULL, NULL },
                { "reset-base-params", 'r', POPT_ARG_NONE, NULL, OPT_RESET_BASE_PARAMS, NULL, NULL },
-               { "retry-duration", '\0', POPT_ARG_LONGLONG, &retry_duration, OPT_RETRY_DURATION, NULL, NULL },
+               { "retry-duration", '\0', POPT_ARG_LONG, &retry_duration, OPT_RETRY_DURATION, NULL, NULL },
                { "value", '\0', POPT_ARG_STRING, NULL, OPT_VALUE, NULL, NULL },
                { NULL, 0, '\0', NULL, 0, NULL, NULL },
        };
@@ -2478,7 +2503,7 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[],
                                abort();
                        }
 
-                       assert(cur_base_params);
+                       BT_ASSERT(cur_base_params);
                        bt_put(cur_cfg_comp->params);
                        cur_cfg_comp->params = bt_value_copy(cur_base_params);
                        if (!cur_cfg_comp->params) {
@@ -2585,7 +2610,7 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[],
                        break;
                case OPT_RETRY_DURATION:
                        if (retry_duration < 0) {
-                               printf_err("--retry-duration option's argument must be positive or 0: %lld\n",
+                               printf_err("--retry-duration option's argument must be positive or 0: %ld\n",
                                        retry_duration);
                                goto error;
                        }
@@ -2704,10 +2729,10 @@ struct bt_config *bt_config_run_from_args_array(struct bt_value *run_args,
                struct bt_value *arg_value = bt_value_array_get(run_args, i);
                const char *arg;
 
-               assert(arg_value);
+               BT_ASSERT(arg_value);
                ret = bt_value_string_get(arg_value, &arg);
-               assert(ret == 0);
-               assert(arg);
+               BT_ASSERT(ret == 0);
+               BT_ASSERT(arg);
                argv[i + 1] = arg;
                bt_put(arg_value);
        }
@@ -3028,7 +3053,7 @@ int append_run_args_for_implicit_component(
                        goto error;
                }
 
-               assert(bt_value_is_string(elem));
+               BT_ASSERT(bt_value_is_string(elem));
                if (bt_value_string_get(elem, &arg)) {
                        goto error;
                }
@@ -3053,7 +3078,7 @@ end:
 static
 void finalize_implicit_component_args(struct implicit_component_args *args)
 {
-       assert(args);
+       BT_ASSERT(args);
 
        if (args->comp_arg) {
                g_string_free(args->comp_arg, TRUE);
@@ -3109,9 +3134,9 @@ static
 void append_implicit_component_param(struct implicit_component_args *args,
        const char *key, const char *value)
 {
-       assert(args);
-       assert(key);
-       assert(value);
+       BT_ASSERT(args);
+       BT_ASSERT(key);
+       BT_ASSERT(value);
        append_param_arg(args->params_arg, key, value);
 }
 
@@ -3121,9 +3146,9 @@ int append_implicit_component_extra_param(struct implicit_component_args *args,
 {
        int ret = 0;
 
-       assert(args);
-       assert(key);
-       assert(value);
+       BT_ASSERT(args);
+       BT_ASSERT(key);
+       BT_ASSERT(value);
 
        if (bt_value_array_append_string(args->extra_params, "--key")) {
                print_err_oom();
@@ -3342,9 +3367,9 @@ int convert_auto_connect(struct bt_value *run_args,
        GList *filter_prev;
        GList *sink_at = sink_names;
 
-       assert(source_names);
-       assert(filter_names);
-       assert(sink_names);
+       BT_ASSERT(source_names);
+       BT_ASSERT(filter_names);
+       BT_ASSERT(sink_names);
 
        /* Connect all sources to the first filter */
        for (source_at = source_names; source_at != NULL; source_at = g_list_next(source_at)) {
@@ -3403,7 +3428,7 @@ int split_timerange(const char *arg, char **begin, char **end)
        GString *g_begin = NULL;
        GString *g_end = NULL;
 
-       assert(arg);
+       BT_ASSERT(arg);
 
        if (*ch == '[') {
                ch++;
@@ -3421,8 +3446,8 @@ int split_timerange(const char *arg, char **begin, char **end)
                goto error;
        }
 
-       assert(begin);
-       assert(end);
+       BT_ASSERT(begin);
+       BT_ASSERT(end);
        *begin = g_begin->str;
        *end = g_end->str;
        g_string_free(g_begin, FALSE);
@@ -3452,7 +3477,7 @@ int g_list_prepend_gstring(GList **list, const char *string)
        int ret = 0;
        GString *gs = g_string_new(string);
 
-       assert(list);
+       BT_ASSERT(list);
 
        if (!gs) {
                print_err_oom();
@@ -4104,7 +4129,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                case OPT_DEBUG_INFO_DIR:
                        implicit_debug_info_args.exists = true;
                        ret = append_implicit_component_extra_param(
-                               &implicit_debug_info_args, "dir", arg);
+                               &implicit_debug_info_args, "debug-info-dir", arg);
                        if (ret) {
                                goto error;
                        }
@@ -4319,6 +4344,13 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                gs_leftover = leftovers->data;
                g_string_assign(cfg->cmd_data.print_ctf_metadata.path,
                        gs_leftover->str);
+
+               if (output) {
+                       g_string_assign(
+                               cfg->cmd_data.print_ctf_metadata.output_path,
+                               output);
+               }
+
                goto end;
        }
 
@@ -4406,6 +4438,13 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
 
                                g_string_assign(cfg->cmd_data.print_lttng_live_sessions.url,
                                        gs_leftover->str);
+
+                               if (output) {
+                                       g_string_assign(
+                                               cfg->cmd_data.print_lttng_live_sessions.output_path,
+                                               output);
+                               }
+
                                goto end;
                        }
 
@@ -4635,9 +4674,9 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                        GString *quoted = NULL;
                        const char *arg_to_print;
 
-                       assert(arg_value);
+                       BT_ASSERT(arg_value);
                        ret = bt_value_string_get(arg_value, &arg);
-                       assert(ret == 0);
+                       BT_ASSERT(ret == 0);
                        BT_PUT(arg_value);
 
                        if (print_run_args) {
@@ -4736,7 +4775,7 @@ void print_gen_usage(FILE *fp)
        fprintf(fp, "\n");
        fprintf(fp, "  -d, --debug          Enable debug mode (same as --log-level=V)\n");
        fprintf(fp, "  -h, --help           Show this help and quit\n");
-       fprintf(fp, "      --log-level=LVL  Set all log levels to LVL (`N`, `V`, `D`,\n");
+       fprintf(fp, "  -l, --log-level=LVL  Set all log levels to LVL (`N`, `V`, `D`,\n");
        fprintf(fp, "                       `I`, `W` (default), `E`, or `F`)\n");
        fprintf(fp, "  -v, --verbose        Enable verbose mode (same as --log-level=I)\n");
        fprintf(fp, "  -V, --version        Show version and quit\n");
@@ -4843,7 +4882,8 @@ struct bt_config *bt_config_cli_args_create(int argc, const char *argv[],
                                 */
                                log_level = 'I';
                        }
-               } else if (strcmp(cur_arg, "--log-level") == 0) {
+               } else if (strcmp(cur_arg, "--log-level") == 0 ||
+                               strcmp(cur_arg, "-l") == 0) {
                        if (!next_arg) {
                                printf_err("Missing log level value for --log-level option\n");
                                *retcode = 1;
@@ -4862,6 +4902,16 @@ struct bt_config *bt_config_cli_args_create(int argc, const char *argv[],
                } else if (strncmp(cur_arg, "--log-level=", 12) == 0) {
                        const char *arg = &cur_arg[12];
 
+                       log_level = log_level_from_arg(arg);
+                       if (log_level == 'U') {
+                               printf_err("Invalid argument for --log-level option:\n    %s\n",
+                                       arg);
+                               *retcode = 1;
+                               goto end;
+                       }
+               } else if (strncmp(cur_arg, "-l", 2) == 0) {
+                       const char *arg = &cur_arg[2];
+
                        log_level = log_level_from_arg(arg);
                        if (log_level == 'U') {
                                printf_err("Invalid argument for --log-level option:\n    %s\n",
@@ -4921,8 +4971,8 @@ struct bt_config *bt_config_cli_args_create(int argc, const char *argv[],
                goto end;
        }
 
-       assert(command_argv);
-       assert(command_argc >= 0);
+       BT_ASSERT(command_argv);
+       BT_ASSERT(command_argc >= 0);
 
        switch (command_type) {
        case COMMAND_TYPE_RUN:
This page took 0.029122 seconds and 4 git commands to generate.