tools: Fix printing commands help

This commit is contained in:
Thibault Saunier 2016-07-28 14:24:07 -04:00
parent b612d015ca
commit be66877d95
4 changed files with 82 additions and 43 deletions

View file

@ -205,42 +205,75 @@ _ges_command_line_formatter_add_effect (GESTimeline * timeline,
static GOptionEntry timeline_parsing_options[] = { static GOptionEntry timeline_parsing_options[] = {
{"clip", 'c', 0.0, G_OPTION_ARG_CALLBACK, {"clip", 'c', 0.0, G_OPTION_ARG_CALLBACK,
&_ges_command_line_formatter_add_clip, &_ges_command_line_formatter_add_clip,
"", "<clip uri> - Adds a clip in the timeline.",
"Adds a clip in the timeline\n" " * s=, start The start position of the element inside the layer.\n"
" * start - s : The start position of the element inside the layer.\n" " * d=, duration The duration of the clip.\n"
" * duration - d: The duration of the clip.\n" " * i=, inpoint The inpoint of the clip.\n"
" * inpoint - i : The inpoint of the clip.\n" " * tt=, track-types The type of the tracks where the clip should be used:\n"
" * track-types - tt: The type of the tracks where the clip should be used:\n"
" Examples:\n" " Examples:\n"
" * audio / a\n" " * audio / a\n"
" * video / v\n" " * video / v\n"
" * audio+video / a+v\n" " * audio+video / a+v\n"
" Will default to all the media types in the clip that match the global track-types\n"}, " (Will default to all the media types in the clip that match the global track-types)\n"},
{"effect", 'e', 0.0, G_OPTION_ARG_CALLBACK, {"effect", 'e', 0.0, G_OPTION_ARG_CALLBACK,
&_ges_command_line_formatter_add_effect, "", &_ges_command_line_formatter_add_effect,
"Adds an effect as specified by 'bin-description'\n" "<effect bin description> - Adds an effect as specified by 'bin-description'.",
" * bin-description - d: The description of the effect bin with a gst-launch-style pipeline description.\n" " * d=, bin-description The description of the effect bin with a gst-launch-style pipeline description.\n"
" * element-name - e : The name of the element to apply the effect on.\n"}, " * e=, element-name The name of the element to apply the effect on.\n"},
{"test-clip", 0, 0.0, G_OPTION_ARG_CALLBACK, {"test-clip", 0, 0.0, G_OPTION_ARG_CALLBACK,
&_ges_command_line_formatter_add_test_clip, &_ges_command_line_formatter_add_test_clip,
"", "<test clip pattern> - Add a test clip in the timeline.",
"Add a test clip in the timeline\n" " * s=, start The start position of the element inside the layer.\n"
" * start -s : The start position of the element inside the layer.\n" " * d=, duration The duration of the clip.\n"
" * duration -d : The duration of the clip." " * i=, inpoint The inpoint of the clip.\n"},
" * inpoint - i : The inpoint of the clip.\n"}, {"set-", 0, 0.0, G_OPTION_ARG_CALLBACK,
NULL,
"<property name> <value> - Set a property on the last added element."
" Any child property that exists on the previously added element"
" can be used as <property name>", NULL},
}; };
GOptionGroup * gchar *
_ges_command_line_formatter_get_option_group (void) ges_command_line_formatter_get_help (gint nargs, gchar ** commands)
{ {
GOptionGroup *group; gint i;
gchar *help = NULL;
group = g_option_group_new ("GESCommandLineFormatter", for (i = 0; i < G_N_ELEMENTS (timeline_parsing_options); i++) {
"GStreamer Editing Services command line options to describe a timeline", gboolean print = nargs == 0;
"Show GStreamer Options", NULL, NULL);
g_option_group_add_entries (group, timeline_parsing_options);
return group; if (!print) {
gint j;
for (j = 0; j < nargs; j++) {
gchar *cname = commands[j][0] == '+' ? &commands[j][1] : commands[j];
if (!g_strcmp0 (cname, timeline_parsing_options[i].long_name)) {
print = TRUE;
break;
}
}
}
if (print) {
gchar *tmp = g_strdup_printf ("%s %s%s %s\n", help ? help : "",
timeline_parsing_options[i].arg_description ? "+" : "",
timeline_parsing_options[i].long_name,
timeline_parsing_options[i].description);
g_free (help);
help = tmp;
if (timeline_parsing_options[i].arg_description) {
tmp = g_strdup_printf ("%s Properties:\n%s\n", help,
timeline_parsing_options[i].arg_description);
g_free (help);
help = tmp;
}
}
}
return help;
} }

View file

@ -51,6 +51,7 @@ struct _GESCommandLineFormatter
}; };
GType ges_command_line_formatter_get_type (void); GType ges_command_line_formatter_get_type (void);
gchar * ges_command_line_formatter_get_help (gint nargs, gchar ** commands);
G_END_DECLS G_END_DECLS

View file

@ -316,13 +316,6 @@ ges_base_xml_formatter_set_timeline_properties(GESBaseXmlFormatter * self,
const gchar *properties, const gchar *properties,
const gchar *metadatas); const gchar *metadatas);
/****************************************************
* GESCommandLineFormatter *
****************************************************/
G_GNUC_INTERNAL GOptionGroup *
_ges_command_line_formatter_get_option_group (void);
/**************************************************** /****************************************************
* GESContainer * * GESContainer *
****************************************************/ ****************************************************/

View file

@ -22,14 +22,18 @@
#include "ges-launcher.h" #include "ges-launcher.h"
static void static void
_print_all_commands (void) _print_all_commands (gint nargs, gchar ** commands)
{ {
/* Yeah I know very fancy */ gchar *help;
if (nargs == 0)
g_print ("Available ges-launch-1.0 commands:\n\n"); g_print ("Available ges-launch-1.0 commands:\n\n");
g_print (" %-9s %-11s %-15s %-10s\n\n", "+clip", "+effect", "+test-clip",
"set-"); help = ges_command_line_formatter_get_help (nargs, commands);
g_print ("See ges-launch-1.0 help <command> or ges-launch-1.0 help <guide> "
"to read about a specific command or a given guide\n"); g_print ("%s", help);
g_free (help);
} }
static void static void
@ -44,7 +48,15 @@ _check_command_help (int argc, gchar ** argv)
*/ */
if (!g_strcmp0 (argv[1], "help")) { if (!g_strcmp0 (argv[1], "help")) {
_print_all_commands (); gint nargs = 0;
gchar **commands = NULL;
if (argc > 2) {
nargs = argc - 2;
commands = &argv[2];
}
_print_all_commands (nargs, commands);
exit (0); exit (0);
} }