From 22e224622e936c4eba550405f5631c5297c165be Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Fri, 10 Feb 2017 01:12:57 -0500 Subject: [PATCH] babeltrace(1): add help command MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The new `help` command shows all the information of a specific plugin or of a specific component class. The syntax to get help for a specific plugin is: babeltrace help PLUGIN and for a specific component class: babeltrace help (--source | --filter | --sink) PLUGIN.COMPCLS The full help of the component class (bt_component_class_get_help()) is printed when available. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- converter/babeltrace-cfg.c | 322 ++++++++++++++++++++++++++++++-- converter/babeltrace-cfg.h | 12 ++ converter/babeltrace.c | 224 +++++++++++++++++----- lib/component/component-class.c | 6 +- 4 files changed, 498 insertions(+), 66 deletions(-) diff --git a/converter/babeltrace-cfg.c b/converter/babeltrace-cfg.c index e0997357..999c773f 100644 --- a/converter/babeltrace-cfg.c +++ b/converter/babeltrace-cfg.c @@ -826,11 +826,20 @@ void bt_config_destroy(struct bt_object *obj) BT_PUT(cfg->cmd_data.convert.plugin_paths); break; - case BT_CONFIG_COMMAND_LIST_PLUGINS: BT_PUT(cfg->cmd_data.list_plugins.plugin_paths); break; + case BT_CONFIG_COMMAND_HELP: + BT_PUT(cfg->cmd_data.help.plugin_paths); + + if (cfg->cmd_data.help.plugin_name) { + g_string_free(cfg->cmd_data.help.plugin_name, TRUE); + } + if (cfg->cmd_data.help.component_name) { + g_string_free(cfg->cmd_data.help.component_name, TRUE); + } + break; default: assert(false); } @@ -1985,6 +1994,7 @@ enum { OPT_DEBUG_INFO_TARGET_PREFIX, OPT_END, OPT_FIELDS, + OPT_FILTER, OPT_HELP, OPT_INPUT_FORMAT, OPT_LIST, @@ -2251,6 +2261,276 @@ end: return cfg; } +static struct bt_config *bt_config_help_create( + struct bt_value *initial_plugin_paths) +{ + struct bt_config *cfg; + + /* Create config */ + cfg = bt_config_base_create(BT_CONFIG_COMMAND_HELP); + if (!cfg) { + print_err_oom(); + goto error; + } + + if (initial_plugin_paths) { + cfg->cmd_data.help.plugin_paths = + bt_get(initial_plugin_paths); + } else { + cfg->cmd_data.help.plugin_paths = + bt_value_array_create(); + if (!cfg->cmd_data.help.plugin_paths) { + print_err_oom(); + goto error; + } + } + + cfg->cmd_data.help.plugin_name = g_string_new(NULL); + if (!cfg->cmd_data.help.plugin_name) { + print_err_oom(); + goto error; + } + + cfg->cmd_data.help.component_name = g_string_new(NULL); + if (!cfg->cmd_data.help.component_name) { + print_err_oom(); + goto error; + } + + goto end; + +error: + BT_PUT(cfg); + +end: + return cfg; +} + +/* + * Prints the help command usage. + */ +static +void print_help_usage(FILE *fp) +{ + fprintf(fp, "Usage: babeltrace [GENERAL OPTIONS] help [OPTIONS] PLUGIN\n"); + fprintf(fp, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --source PLUGIN.COMPCLS\n"); + fprintf(fp, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --filter PLUGIN.COMPCLS\n"); + fprintf(fp, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --sink PLUGIN.COMPCLS\n"); + fprintf(fp, "\n"); + fprintf(fp, "Options:\n"); + fprintf(fp, "\n"); + fprintf(fp, " --filter=PLUGIN.COMPCLS Get help for the filter component class\n"); + fprintf(fp, " COMPCLS found in the plugin PLUGIN\n"); + fprintf(fp, " --omit-home-plugin-path Omit home plugins from plugin search path\n"); + fprintf(fp, " (~/.local/lib/babeltrace/plugins)\n"); + fprintf(fp, " --omit-system-plugin-path Omit system plugins from plugin search path\n"); + fprintf(fp, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n"); + fprintf(fp, " dynamic plugins can be loaded\n"); + fprintf(fp, " --sink=PLUGIN.COMPCLS Get help for the sink component class\n"); + fprintf(fp, " COMPCLS found in the plugin PLUGIN\n"); + fprintf(fp, " --source=PLUGIN.COMPCLS Get help for the source component class\n"); + fprintf(fp, " COMPCLS found in the plugin PLUGIN\n"); + fprintf(fp, " -h --help Show this help and quit\n"); + fprintf(fp, "\n"); + fprintf(fp, "See `babeltrace --help` for the list of general options.\n"); + fprintf(fp, "\n"); + fprintf(fp, "Use `babeltrace list-plugins` to show the list of available plugins.\n"); +} + +static struct poptOption help_long_options[] = { + /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ + { "filter", '\0', POPT_ARG_STRING, NULL, OPT_FILTER, NULL, NULL }, + { "help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL }, + { "omit-home-plugin-path", '\0', POPT_ARG_NONE, NULL, OPT_OMIT_HOME_PLUGIN_PATH, NULL, NULL }, + { "omit-system-plugin-path", '\0', POPT_ARG_NONE, NULL, OPT_OMIT_SYSTEM_PLUGIN_PATH, NULL, NULL }, + { "plugin-path", '\0', POPT_ARG_STRING, NULL, OPT_PLUGIN_PATH, NULL, NULL }, + { "sink", '\0', POPT_ARG_STRING, NULL, OPT_SINK, NULL, NULL }, + { "source", '\0', POPT_ARG_STRING, NULL, OPT_SOURCE, NULL, NULL }, + { NULL, 0, 0, NULL, 0, NULL, NULL }, +}; + +/* + * Creates a Babeltrace config object from the arguments of a help + * command. + * + * *retcode is set to the appropriate exit code to use. + */ +struct bt_config *bt_config_help_from_args(int argc, const char *argv[], + int *retcode, bool omit_system_plugin_path, + bool omit_home_plugin_path, + struct bt_value *initial_plugin_paths) +{ + poptContext pc = NULL; + char *arg = NULL; + int opt; + int ret; + struct bt_config *cfg = NULL; + const char *leftover; + char *plugin_name = NULL, *component_name = NULL; + char *plugin_comp_cls_names = NULL; + + *retcode = 0; + cfg = bt_config_help_create(initial_plugin_paths); + if (!cfg) { + print_err_oom(); + goto error; + } + + cfg->cmd_data.help.comp_cls_type = BT_COMPONENT_CLASS_TYPE_UNKNOWN; + cfg->cmd_data.help.omit_system_plugin_path = omit_system_plugin_path; + cfg->cmd_data.help.omit_home_plugin_path = omit_home_plugin_path; + ret = append_env_var_plugin_paths(cfg->cmd_data.help.plugin_paths); + if (ret) { + printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n"); + goto error; + } + + /* Parse options */ + pc = poptGetContext(NULL, argc, (const char **) argv, + help_long_options, 0); + if (!pc) { + printf_err("Cannot get popt context\n"); + goto error; + } + + poptReadDefaultConfig(pc, 0); + + while ((opt = poptGetNextOpt(pc)) > 0) { + arg = poptGetOptArg(pc); + + switch (opt) { + case OPT_PLUGIN_PATH: + if (bt_common_is_setuid_setgid()) { + printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n"); + } else { + if (bt_config_append_plugin_paths( + cfg->cmd_data.help.plugin_paths, + arg)) { + printf_err("Invalid --plugin-path option's argument:\n %s\n", + arg); + goto error; + } + } + break; + case OPT_OMIT_SYSTEM_PLUGIN_PATH: + cfg->cmd_data.help.omit_system_plugin_path = true; + break; + case OPT_OMIT_HOME_PLUGIN_PATH: + cfg->cmd_data.help.omit_home_plugin_path = true; + break; + case OPT_SOURCE: + case OPT_FILTER: + case OPT_SINK: + if (cfg->cmd_data.help.comp_cls_type != + BT_COMPONENT_CLASS_TYPE_UNKNOWN) { + printf_err("Cannot specify more than one plugin and component class:\n %s\n", + arg); + goto error; + } + + switch (opt) { + case OPT_SOURCE: + cfg->cmd_data.help.comp_cls_type = + BT_COMPONENT_CLASS_TYPE_SOURCE; + break; + case OPT_FILTER: + cfg->cmd_data.help.comp_cls_type = + BT_COMPONENT_CLASS_TYPE_FILTER; + break; + case OPT_SINK: + cfg->cmd_data.help.comp_cls_type = + BT_COMPONENT_CLASS_TYPE_SINK; + break; + default: + assert(false); + } + plugin_comp_cls_names = strdup(arg); + if (!plugin_comp_cls_names) { + print_err_oom(); + goto error; + } + break; + case OPT_HELP: + print_help_usage(stdout); + *retcode = -1; + BT_PUT(cfg); + goto end; + default: + printf_err("Unknown command-line option specified (option code %d)\n", + opt); + goto error; + } + + free(arg); + arg = NULL; + } + + /* Check for option parsing error */ + if (opt < -1) { + printf_err("While parsing command-line options, at option %s: %s\n", + poptBadOption(pc, 0), poptStrerror(opt)); + goto error; + } + + leftover = poptGetArg(pc); + if (leftover) { + if (cfg->cmd_data.help.comp_cls_type != + BT_COMPONENT_CLASS_TYPE_UNKNOWN) { + printf_err("Cannot specify plugin name and --source/--filter/--sink component class:\n %s\n", + leftover); + goto error; + } + + g_string_assign(cfg->cmd_data.help.plugin_name, leftover); + } else { + if (cfg->cmd_data.help.comp_cls_type == + BT_COMPONENT_CLASS_TYPE_UNKNOWN) { + print_help_usage(stdout); + *retcode = -1; + BT_PUT(cfg); + goto end; + } + + plugin_component_names_from_arg(plugin_comp_cls_names, + &plugin_name, &component_name); + if (plugin_name && component_name) { + g_string_assign(cfg->cmd_data.help.plugin_name, plugin_name); + g_string_assign(cfg->cmd_data.help.component_name, + component_name); + } else { + printf_err("Invalid --source/--filter/--sink option's argument:\n %s\n", + plugin_comp_cls_names); + goto error; + } + } + + if (append_home_and_system_plugin_paths( + cfg->cmd_data.help.plugin_paths, + cfg->cmd_data.help.omit_system_plugin_path, + cfg->cmd_data.help.omit_home_plugin_path)) { + printf_err("Cannot append home and system plugin paths\n"); + goto error; + } + + goto end; + +error: + *retcode = 1; + BT_PUT(cfg); + +end: + free(plugin_comp_cls_names); + g_free(plugin_name); + g_free(component_name); + + if (pc) { + poptFreeContext(pc); + } + + free(arg); + return cfg; +} + /* * Prints the list-plugins command usage. */ @@ -2269,6 +2549,8 @@ void print_list_plugins_usage(FILE *fp) fprintf(fp, " -h --help Show this help and quit\n"); fprintf(fp, "\n"); fprintf(fp, "See `babeltrace --help` for the list of general options.\n"); + fprintf(fp, "\n"); + fprintf(fp, "Use `babeltrace help` to get help for a specific plugin or component class.\n"); } static struct poptOption list_plugins_long_options[] = { @@ -2398,7 +2680,6 @@ end: return cfg; } - /* * Prints the legacy, Babeltrace 1.x command usage. Those options are * still compatible in Babeltrace 2.x, but it is recommended to use @@ -2665,15 +2946,15 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], /* Note: implicit source never gets positional base params. */ implicit_source_comp = bt_config_component_from_arg(DEFAULT_SOURCE_COMPONENT_NAME); - if (implicit_source_comp) { - cur_cfg_comp = implicit_source_comp; - cur_is_implicit_source = true; - use_implicit_source = true; - } else { - printf_debug("Cannot find implicit source plugin `%s`", - DEFAULT_SOURCE_COMPONENT_NAME); + if (!implicit_source_comp) { + print_err_oom(); + goto error; } + cur_cfg_comp = implicit_source_comp; + cur_is_implicit_source = true; + use_implicit_source = true; + /* Parse options */ pc = poptGetContext(NULL, argc, (const char **) argv, convert_long_options, 0); @@ -3238,6 +3519,7 @@ void print_gen_usage(FILE *fp) fprintf(fp, "Available commands:\n"); fprintf(fp, "\n"); fprintf(fp, " convert Build a trace conversion graph and run it (default)\n"); + fprintf(fp, " help Get help for a plugin or a component class\n"); fprintf(fp, " list-plugins List available plugins and their content\n"); fprintf(fp, "\n"); fprintf(fp, "Use `babeltrace COMMAND --help` to show the help of COMMAND.\n"); @@ -3285,20 +3567,18 @@ struct bt_config *bt_config_from_args(int argc, const char *argv[], print_legacy_usage(stdout); goto end; } else { + bool has_command = true; + /* * First unknown argument: is it a known command * name? */ if (strcmp(cur_arg, "convert") == 0) { command = BT_CONFIG_COMMAND_CONVERT; - command_argv = &argv[i]; - command_argc = argc - i; - command_name = cur_arg; } else if (strcmp(cur_arg, "list-plugins") == 0) { command = BT_CONFIG_COMMAND_LIST_PLUGINS; - command_argv = &argv[i]; - command_argc = argc - i; - command_name = cur_arg; + } else if (strcmp(cur_arg, "help") == 0) { + command = BT_CONFIG_COMMAND_HELP; } else { /* * Unknown argument, but not a known @@ -3309,6 +3589,13 @@ struct bt_config *bt_config_from_args(int argc, const char *argv[], command = BT_CONFIG_COMMAND_CONVERT; command_argv = argv; command_argc = argc; + has_command = false; + } + + if (has_command) { + command_argv = &argv[i]; + command_argc = argc - i; + command_name = cur_arg; } break; } @@ -3339,6 +3626,11 @@ struct bt_config *bt_config_from_args(int argc, const char *argv[], command_argv, retcode, omit_system_plugin_path, omit_home_plugin_path, initial_plugin_paths); break; + case BT_CONFIG_COMMAND_HELP: + config = bt_config_help_from_args(command_argc, + command_argv, retcode, omit_system_plugin_path, + omit_home_plugin_path, initial_plugin_paths); + break; default: assert(false); } diff --git a/converter/babeltrace-cfg.h b/converter/babeltrace-cfg.h index 20c16066..4245012c 100644 --- a/converter/babeltrace-cfg.h +++ b/converter/babeltrace-cfg.h @@ -31,6 +31,7 @@ #include #include #include +#include #include struct bt_config_component { @@ -43,6 +44,7 @@ struct bt_config_component { enum bt_config_command { BT_CONFIG_COMMAND_CONVERT, BT_CONFIG_COMMAND_LIST_PLUGINS, + BT_CONFIG_COMMAND_HELP, }; struct bt_config { @@ -73,6 +75,16 @@ struct bt_config { bool omit_system_plugin_path; bool omit_home_plugin_path; } list_plugins; + + /* BT_CONFIG_COMMAND_HELP */ + struct { + struct bt_value *plugin_paths; + bool omit_system_plugin_path; + bool omit_home_plugin_path; + enum bt_component_class_type comp_cls_type; + GString *plugin_name; + GString *component_name; + } help; } cmd_data; }; diff --git a/converter/babeltrace.c b/converter/babeltrace.c index 65d2ec93..ddb3b0ee 100644 --- a/converter/babeltrace.c +++ b/converter/babeltrace.c @@ -541,6 +541,169 @@ end: return ret; } +static void print_plugin_info(struct bt_plugin *plugin) +{ + unsigned int major, minor, patch; + const char *extra; + enum bt_plugin_status version_status; + const char *plugin_name; + const char *path; + const char *author; + const char *license; + const char *plugin_description; + + plugin_name = bt_plugin_get_name(plugin); + path = bt_plugin_get_path(plugin); + author = bt_plugin_get_author(plugin); + license = bt_plugin_get_license(plugin); + plugin_description = bt_plugin_get_description(plugin); + version_status = bt_plugin_get_version(plugin, &major, &minor, + &patch, &extra); + printf("%s%s%s%s:\n", bt_common_color_bold(), + bt_common_color_fg_blue(), plugin_name, + bt_common_color_reset()); + printf(" %sPath%s: %s\n", bt_common_color_bold(), + bt_common_color_reset(), path ? path : "(None)"); + + if (version_status == BT_PLUGIN_STATUS_OK) { + printf(" %sVersion%s: %u.%u.%u", + bt_common_color_bold(), bt_common_color_reset(), + major, minor, patch); + + if (extra) { + printf("%s", extra); + } + + printf("\n"); + } + + printf(" %sDescription%s: %s\n", bt_common_color_bold(), + bt_common_color_reset(), + plugin_description ? plugin_description : "(None)"); + printf(" %sAuthor%s: %s\n", bt_common_color_bold(), + bt_common_color_reset(), author ? author : "(Unknown)"); + printf(" %sLicense%s: %s\n", bt_common_color_bold(), + bt_common_color_reset(), + license ? license : "(Unknown)"); +} + +static void print_plugin_comp_cls_opt(FILE *fh, const char *plugin_name, + const char *comp_cls_name, enum bt_component_class_type type) +{ + fprintf(fh, "%s%s--%s%s %s%s%s.%s%s%s", + bt_common_color_bold(), + bt_common_color_fg_cyan(), + component_type_str(type), + bt_common_color_fg_default(), + bt_common_color_fg_blue(), + plugin_name, + bt_common_color_fg_default(), + bt_common_color_fg_yellow(), + comp_cls_name, + bt_common_color_reset()); +} + +static int cmd_help(struct bt_config *cfg) +{ + int ret; + struct bt_plugin *plugin = NULL; + size_t i; + + ret = load_all_plugins(cfg->cmd_data.list_plugins.plugin_paths); + if (ret) { + goto end; + } + + plugin = find_plugin(cfg->cmd_data.help.plugin_name->str); + if (!plugin) { + fprintf(stderr, "%s%sCannot find plugin %s%s%s\n", + bt_common_color_bold(), bt_common_color_fg_red(), + bt_common_color_fg_blue(), + cfg->cmd_data.help.plugin_name->str, + bt_common_color_reset()); + ret = -1; + goto end; + } + + print_plugin_info(plugin); + printf(" %sComponent classes%s: %d\n", + bt_common_color_bold(), + bt_common_color_reset(), + bt_plugin_get_component_class_count(plugin)); + + + if (cfg->cmd_data.help.comp_cls_type != + BT_COMPONENT_CLASS_TYPE_UNKNOWN) { + struct bt_component_class *needed_comp_cls = + find_component_class( + cfg->cmd_data.help.plugin_name->str, + cfg->cmd_data.help.component_name->str, + cfg->cmd_data.help.comp_cls_type); + + if (!needed_comp_cls) { + fprintf(stderr, "\n%s%sCannot find component class %s", + bt_common_color_bold(), + bt_common_color_fg_red(), + bt_common_color_reset()); + print_plugin_comp_cls_opt(stderr, + cfg->cmd_data.help.plugin_name->str, + cfg->cmd_data.help.component_name->str, + cfg->cmd_data.help.comp_cls_type); + fprintf(stderr, "\n"); + ret = -1; + goto end; + } + + bt_put(needed_comp_cls); + } + + for (i = 0; i < bt_plugin_get_component_class_count(plugin); i++) { + struct bt_component_class *comp_cls = + bt_plugin_get_component_class(plugin, i); + const char *comp_class_name = + bt_component_class_get_name(comp_cls); + const char *comp_class_description = + bt_component_class_get_description(comp_cls); + const char *comp_class_help = + bt_component_class_get_help(comp_cls); + enum bt_component_class_type type = + bt_component_class_get_type(comp_cls); + + assert(comp_cls); + + if (cfg->cmd_data.help.comp_cls_type != + BT_COMPONENT_CLASS_TYPE_UNKNOWN) { + if (strcmp(cfg->cmd_data.help.component_name->str, + comp_class_name) != 0 && + type == + cfg->cmd_data.help.comp_cls_type) { + bt_put(comp_cls); + continue; + } + } + + printf("\n"); + print_plugin_comp_cls_opt(stdout, + cfg->cmd_data.help.plugin_name->str, + comp_class_name, + type); + printf("\n"); + printf(" %sDescription%s: %s\n", bt_common_color_bold(), + bt_common_color_reset(), + comp_class_description ? comp_class_description : "(None)"); + + if (comp_class_help) { + printf("\n%s\n", comp_class_help); + } + + bt_put(comp_cls); + } + +end: + bt_put(plugin); + return ret; +} + static int cmd_list_plugins(struct bt_config *cfg) { int ret; @@ -551,6 +714,9 @@ static int cmd_list_plugins(struct bt_config *cfg) goto end; } + printf("From the following plugin paths:\n\n"); + print_value(cfg->cmd_data.list_plugins.plugin_paths, 2); + printf("\n"); plugins_count = loaded_plugins->len; if (plugins_count == 0) { fprintf(stderr, "%s%sNo plugins found.%s\n", @@ -581,47 +747,11 @@ static int cmd_list_plugins(struct bt_config *cfg) for (i = 0; i < plugins_count; i++) { int j; struct bt_plugin *plugin = g_ptr_array_index(loaded_plugins, i); - unsigned int major, minor, patch; - const char *extra; - enum bt_plugin_status version_status; - const char *plugin_name = bt_plugin_get_name(plugin); - const char *path = bt_plugin_get_path(plugin); - const char *author = bt_plugin_get_author(plugin); - const char *license = bt_plugin_get_license(plugin); - const char *plugin_description = - bt_plugin_get_description(plugin); component_classes_count = bt_plugin_get_component_class_count(plugin); - version_status = bt_plugin_get_version(plugin, &major, &minor, - &patch, &extra); - - printf("\n%s%s%s%s:\n", bt_common_color_bold(), - bt_common_color_fg_blue(), plugin_name, - bt_common_color_reset()); - printf(" %sPath%s: %s\n", bt_common_color_bold(), - bt_common_color_reset(), path ? path : "(None)"); - - if (version_status == BT_PLUGIN_STATUS_OK) { - printf(" %sVersion%s: %u.%u.%u", - bt_common_color_bold(), bt_common_color_reset(), - major, minor, patch); - - if (extra) { - printf("%s", extra); - } - - printf("\n"); - } - - printf(" %sDescription%s: %s\n", bt_common_color_bold(), - bt_common_color_reset(), - plugin_description ? plugin_description : "(None)"); - printf(" %sAuthor%s: %s\n", bt_common_color_bold(), - bt_common_color_reset(), author ? author : "(Unknown)"); - printf(" %sLicense%s: %s\n", bt_common_color_bold(), - bt_common_color_reset(), - license ? license : "(Unknown)"); + printf("\n"); + print_plugin_info(plugin); if (component_classes_count == 0) { printf(" %sComponent classes%s: (None)\n", @@ -643,17 +773,10 @@ static int cmd_list_plugins(struct bt_config *cfg) enum bt_component_class_type type = bt_component_class_get_type(comp_class); - printf(" %s%s--%s%s %s%s%s.%s%s%s", - bt_common_color_bold(), - bt_common_color_fg_cyan(), - component_type_str(type), - bt_common_color_fg_default(), - bt_common_color_fg_blue(), - plugin_name, - bt_common_color_fg_default(), - bt_common_color_fg_yellow(), - comp_class_name, - bt_common_color_reset()); + printf(" "); + print_plugin_comp_cls_opt(stdout, + bt_plugin_get_name(plugin), comp_class_name, + type); if (comp_class_description) { printf(": %s", comp_class_description); @@ -819,6 +942,9 @@ int main(int argc, const char **argv) case BT_CONFIG_COMMAND_LIST_PLUGINS: ret = cmd_list_plugins(cfg); break; + case BT_CONFIG_COMMAND_HELP: + ret = cmd_help(cfg); + break; default: assert(false); } diff --git a/lib/component/component-class.c b/lib/component/component-class.c index a0080421..72bea187 100644 --- a/lib/component/component-class.c +++ b/lib/component/component-class.c @@ -431,14 +431,16 @@ enum bt_component_class_type bt_component_class_get_type( const char *bt_component_class_get_description( struct bt_component_class *component_class) { - return component_class && component_class->description ? + return component_class && component_class->description && + component_class->description->str[0] != '\0' ? component_class->description->str : NULL; } const char *bt_component_class_get_help( struct bt_component_class *component_class) { - return component_class && component_class->help ? + return component_class && component_class->help && + component_class->help->str[0] != '\0' ? component_class->help->str : NULL; } -- 2.34.1