gdbus-tool: Make --dest optional for emit again

Commit faf9440908 made the bash completion more
robust, but in doing so it made the optional --dest argument to `gdbus emit'
mandatory by mistake.

Remove the error case when --dest is not specified. To keep the completion
working, we shuffle the cases around. --dest should be offered up for
completion after --session/--system/--address have been supplied, so we can
complete its argument. Additionally, if --dest isn't specified then we can't
complete --object-path or --signal, so guard these completions accordingly.

https://bugzilla.gnome.org/show_bug.cgi?id=793597
This commit is contained in:
Iain Lane 2018-02-21 12:22:08 +00:00 committed by Philip Withnall
parent 1717a8c965
commit 2a2717062b

View File

@ -653,28 +653,24 @@ handle_emit (gint *argc,
print_names (c, FALSE); print_names (c, FALSE);
goto out; goto out;
} }
if (opt_emit_dest == NULL) if (request_completion && opt_emit_dest != NULL && g_strcmp0 ("--dest", completion_prev) == 0)
{
if (request_completion)
g_print ("--dest \n");
else
g_printerr (_("Error: Destination is not specified\n"));
goto out;
}
if (request_completion && g_strcmp0 ("--dest", completion_prev) == 0)
{ {
print_names (c, g_str_has_prefix (opt_emit_dest, ":")); print_names (c, g_str_has_prefix (opt_emit_dest, ":"));
goto out; goto out;
} }
if (!request_completion && !g_dbus_is_unique_name (opt_emit_dest)) if (!request_completion && opt_emit_dest != NULL && !g_dbus_is_unique_name (opt_emit_dest))
{ {
g_printerr (_("Error: %s is not a valid unique bus name.\n"), opt_emit_dest); g_printerr (_("Error: %s is not a valid unique bus name.\n"), opt_emit_dest);
goto out; goto out;
} }
if (opt_emit_dest == NULL && opt_emit_object_path == NULL && request_completion)
{
g_print ("--dest \n");
}
/* validate and complete object path */ /* validate and complete object path */
if (complete_paths) if (opt_emit_dest != NULL && complete_paths)
{ {
print_paths (c, opt_emit_dest, "/"); print_paths (c, opt_emit_dest, "/");
goto out; goto out;
@ -689,17 +685,20 @@ handle_emit (gint *argc,
} }
if (request_completion && g_strcmp0 ("--object-path", completion_prev) == 0) if (request_completion && g_strcmp0 ("--object-path", completion_prev) == 0)
{ {
gchar *p; if (opt_emit_dest != NULL)
s = g_strdup (opt_emit_object_path);
p = strrchr (s, '/');
if (p != NULL)
{ {
if (p == s) gchar *p;
p++; s = g_strdup (opt_emit_object_path);
*p = '\0'; p = strrchr (s, '/');
if (p != NULL)
{
if (p == s)
p++;
*p = '\0';
}
print_paths (c, opt_emit_dest, s);
g_free (s);
} }
print_paths (c, opt_emit_dest, s);
g_free (s);
goto out; goto out;
} }
if (!request_completion && !g_variant_is_object_path (opt_emit_object_path)) if (!request_completion && !g_variant_is_object_path (opt_emit_object_path))
@ -709,7 +708,7 @@ handle_emit (gint *argc,
} }
/* validate and complete signal (interface + signal name) */ /* validate and complete signal (interface + signal name) */
if (complete_signals) if (opt_emit_dest != NULL && opt_emit_object_path != NULL && complete_signals)
{ {
print_methods_and_signals (c, opt_emit_dest, opt_emit_object_path, FALSE, TRUE); print_methods_and_signals (c, opt_emit_dest, opt_emit_object_path, FALSE, TRUE);
goto out; goto out;
@ -722,7 +721,8 @@ handle_emit (gint *argc,
g_printerr (_("Error: Signal name is not specified\n")); g_printerr (_("Error: Signal name is not specified\n"));
goto out; goto out;
} }
if (request_completion && g_strcmp0 ("--signal", completion_prev) == 0) if (request_completion && opt_emit_dest != NULL && opt_emit_object_path != NULL &&
g_strcmp0 ("--signal", completion_prev) == 0)
{ {
print_methods_and_signals (c, opt_emit_dest, opt_emit_object_path, FALSE, TRUE); print_methods_and_signals (c, opt_emit_dest, opt_emit_object_path, FALSE, TRUE);
goto out; goto out;