validate: inspect: Output valid markdown

So it can be used directly in the documentation Also add a special "all"
argument to `gst-validate-1.0 --inspect-action-type` so we can generate
the documentation for all action types easily.
This commit is contained in:
Thibault Saunier 2018-11-17 12:31:13 -03:00
parent 0a7b23f566
commit 67d4a39602
3 changed files with 75 additions and 58 deletions

View file

@ -841,60 +841,52 @@ static void
print_action_parameter (GString * string, GstValidateActionType * type,
GstValidateActionParameter * param)
{
gint nw = 0;
gchar *desc, *tmp;
gchar *param_head = g_strdup_printf (" %s", param->name);
gchar *tmp_head = g_strdup_printf ("\n %-30s : %s",
param_head, "something");
while (tmp_head[nw] != ':')
nw++;
g_free (tmp_head);
tmp = g_strdup_printf ("\n%*s", nw + 1, " ");
gchar *desc;
g_string_append_printf (string, "\n\n* `%s`:(%s): ", param->name,
param->mandatory ? "mandatory" : "optional");
if (g_strcmp0 (param->description, "")) {
desc =
g_regex_replace (newline_regex, param->description,
-1, 0, tmp, 0, NULL);
desc = g_strdup (param->description);
} else {
desc = g_strdup ("No description");
desc = g_strdup ("__No description__");
}
g_string_append_printf (string, "\n %-30s : %s", param_head, desc);
g_string_append (string, desc);
g_free (desc);
if (param->possible_variables) {
gchar *tmp1 = g_strdup_printf ("\n%*s", nw + 4, " ");
desc =
g_regex_replace (newline_regex,
param->possible_variables, -1, 0, tmp1, 0, NULL);
g_string_append_printf (string, "%sPossible variables:%s%s", tmp,
tmp1, desc);
g_free (tmp1);
param->possible_variables, -1, 0, "\n\n * ", 0, NULL);
g_string_append_printf (string, "\n\n Possible variables:\n\n * %s",
desc);
}
if (param->types) {
gchar *tmp1 = g_strdup_printf ("\n%*s", nw + 4, " ");
desc = g_regex_replace (newline_regex, param->types, -1, 0, tmp1, 0, NULL);
g_string_append_printf (string, "%sPossible types:%s%s", tmp, tmp1, desc);
if (param->types)
g_string_append_printf (string, "\n\n Possible types: `%s`", param->types);
g_free (tmp1);
}
if (!param->mandatory)
g_string_append_printf (string, "\n\n Default: %s", param->def);
if (!param->mandatory) {
g_string_append_printf (string, "%sDefault: %s", tmp, param->def);
}
}
g_string_append_printf (string, "%s%s", tmp,
param->mandatory ? "Mandatory." : "Optional.");
static void
print_action_parameter_prototype (GString * string,
GstValidateActionParameter * param, gboolean is_first)
{
if (!is_first)
g_string_append (string, ",");
g_string_append (string, "\n ");
g_free (tmp);
g_free (param_head);
if (!param->mandatory)
g_string_append (string, "[");
g_string_append (string, param->name);
if (param->types)
g_string_append_printf (string, "=(%s)", param->types);
if (!param->mandatory)
g_string_append (string, "]");
}
void
@ -915,8 +907,8 @@ gst_validate_printf_valist (gpointer source, const gchar * format, va_list args)
} else if (*(GType *) source == GST_TYPE_VALIDATE_ACTION_TYPE) {
gint i;
gchar *desc;
gboolean has_parameters = FALSE;
gboolean is_first = TRUE;
GstValidateActionParameter playback_time_param = {
.name = "playback-time",
@ -924,8 +916,8 @@ gst_validate_printf_valist (gpointer source, const gchar * format, va_list args)
.mandatory = FALSE,
.types = "double,string",
.possible_variables =
"position: The current position in the stream\n"
"duration: The duration of the stream",
"`position`: The current position in the stream\n"
"`duration`: The duration of the stream",
.def = "0.0"
};
@ -944,21 +936,37 @@ gst_validate_printf_valist (gpointer source, const gchar * format, va_list args)
GstValidateActionType *type = GST_VALIDATE_ACTION_TYPE (source);
g_string_assign (string, "\nAction type:");
g_string_append_printf (string, "\n## %s\n\n", type->name);
g_string_append_printf (string, "\n``` validate-scenario\n%s,",
type->name);
if (!IS_CONFIG_ACTION_TYPE (type->flags)) {
print_action_parameter_prototype (string, &playback_time_param,
is_first);
is_first = FALSE;
}
for (i = 0; type->parameters[i].name; i++) {
print_action_parameter_prototype (string, &type->parameters[i],
is_first);
is_first = FALSE;
}
g_string_append (string, ";\n```\n");
g_string_append_printf (string, "\n%s", type->description);
g_string_append_printf (string,
"\n Name: %s\n Implementer namespace: %s",
type->name, type->implementer_namespace);
"\n * Implementer namespace: %s", type->implementer_namespace);
if (IS_CONFIG_ACTION_TYPE (type->flags))
g_string_append_printf (string,
"\n Is config action (meaning it will be executing right "
"\n * Is config action (meaning it will be executing right "
"at the beginning of the execution of the pipeline)");
desc = g_regex_replace (newline_regex, type->description, -1, 0, "\n ",
0, NULL);
g_string_append_printf (string, "\n\n Description: \n %s", desc);
g_free (desc);
if (type->parameters || !IS_CONFIG_ACTION_TYPE (type->flags))
g_string_append_printf (string, "\n\n### Parameters");
if (!IS_CONFIG_ACTION_TYPE (type->flags)) {
g_string_append_printf (string, "\n\n Parameters:");
@ -981,12 +989,12 @@ gst_validate_printf_valist (gpointer source, const gchar * format, va_list args)
g_string_append_printf (string,
"\n optional : "
"Don't raise an error if this action hasn't been executed or failed"
"\n%-32s Possible types:"
"\n%-32s ### Possible types:"
"\n%-32s boolean" "\n%-32s Default: false", "", "", "");
}
if (!has_parameters)
g_string_append_printf (string, "\n\n No Parameters");
g_string_append_printf (string, "\n\n ### No Parameters");
} else if (GST_IS_VALIDATE_REPORTER (source) &&
gst_validate_reporter_get_name (source)) {
g_string_printf (string, "\n%s --> ",

View file

@ -4606,10 +4606,15 @@ gst_validate_print_action_types (const gchar ** wanted_types,
{
GList *tmp;
gint nfound = 0;
gboolean print_all = (num_wanted_types == 1
&& !g_strcmp0 (wanted_types[0], "all"));
if (print_all)
gst_validate_printf (NULL, "# GstValidate action types");
for (tmp = gst_validate_list_action_types (); tmp; tmp = tmp->next) {
GstValidateActionType *atype = (GstValidateActionType *) tmp->data;
gboolean print = FALSE;
gboolean print = print_all;
if (num_wanted_types) {
gint n;
@ -4641,7 +4646,7 @@ gst_validate_print_action_types (const gchar ** wanted_types,
}
}
if (num_wanted_types && num_wanted_types > nfound) {
if (!print_all && num_wanted_types && num_wanted_types > nfound) {
return FALSE;
}
@ -4834,8 +4839,9 @@ init_scenarios (void)
.description = "The starting value of the seek",
.mandatory = TRUE,
.types = "double or string (GstClockTime)",
.possible_variables = "position: The current position in the stream\n"
"duration: The duration of the stream",
.possible_variables =
"`position`: The current position in the stream\n"
"`duration`: The duration of the stream",
NULL
},
{
@ -4876,8 +4882,9 @@ init_scenarios (void)
.description = "The stop value of the seek",
.mandatory = FALSE,
.types = "double or string (GstClockTime)",
.possible_variables = "position: The current position in the stream\n"
"duration: The duration of the stream",
.possible_variables =
"`position`: The current position in the stream\n"
"`duration`: The duration of the stream",
.def ="GST_CLOCK_TIME_NONE",
},
{NULL}

View file

@ -335,7 +335,9 @@ main (int argc, gchar ** argv)
{"inspect-action-type", 't', 0, G_OPTION_ARG_NONE, &inspect_action_type,
"Inspect the available action types with which to write scenarios."
" Specify an action type if you want its full description."
" If no action type is given the full list of available ones gets printed.",
" If no action type is given the full list of available ones gets printed."
"Note that passing \"all\" as action type name, makes it output the"
" full documentation for all types.",
NULL},
{"set-media-info", '\0', 0, G_OPTION_ARG_FILENAME, &media_info,
"Set a media_info XML file descriptor to share information about the"