[glib/wip/laney/gdbus-tool-completion-fixes] gdbus-tool: Make --dest optional for emit again
- From: Iain Lane <iainl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/laney/gdbus-tool-completion-fixes] gdbus-tool: Make --dest optional for emit again
- Date: Mon, 19 Feb 2018 14:05:38 +0000 (UTC)
commit b884b52c7706c761cbe467c427d5ac4c8b364a03
Author: Iain Lane <iain orangesquash org uk>
Date: Mon Feb 19 13:28:53 2018 +0000
gdbus-tool: Make --dest optional for emit again
Commit faf94409083f40ed096565b4f948852323bad697 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 offer up potential arguments. Additionally, if
--dest isn't specified then we can't complete --object-path or --signal,
so guard these completions accordingly.
gio/gdbus-tool.c | 55 ++++++++++++++++++++++++++++++++-----------------------
1 file changed, 32 insertions(+), 23 deletions(-)
---
diff --git a/gio/gdbus-tool.c b/gio/gdbus-tool.c
index 77863a2a0..c31d083c1 100644
--- a/gio/gdbus-tool.c
+++ b/gio/gdbus-tool.c
@@ -583,6 +583,8 @@ handle_emit (gint *argc,
modify_argv0_for_command (argc, argv, "emit");
o = g_option_context_new (NULL);
+ if (request_completion)
+ g_option_context_set_ignore_unknown_options (o, TRUE);
g_option_context_set_help_enabled (o, FALSE);
g_option_context_set_summary (o, _("Emit a signal."));
g_option_context_add_main_entries (o, emit_entries, GETTEXT_PACKAGE);
@@ -651,28 +653,24 @@ handle_emit (gint *argc,
print_names (c, FALSE);
goto out;
}
- if (opt_emit_dest == NULL)
- {
- 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, ":"));
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);
goto out;
}
+ if (opt_emit_dest == NULL && opt_emit_object_path == NULL && request_completion)
+ {
+ g_print ("--dest \n");
+ }
/* validate and complete object path */
- if (complete_paths)
+ if (opt_emit_dest != NULL && complete_paths)
{
print_paths (c, opt_emit_dest, "/");
goto out;
@@ -687,17 +685,20 @@ handle_emit (gint *argc,
}
if (request_completion && g_strcmp0 ("--object-path", completion_prev) == 0)
{
- gchar *p;
- s = g_strdup (opt_emit_object_path);
- p = strrchr (s, '/');
- if (p != NULL)
+ if (opt_emit_dest != NULL)
{
- if (p == s)
- p++;
- *p = '\0';
+ gchar *p;
+ s = g_strdup (opt_emit_object_path);
+ 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;
}
if (!request_completion && !g_variant_is_object_path (opt_emit_object_path))
@@ -707,20 +708,28 @@ handle_emit (gint *argc,
}
/* 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);
goto out;
}
if (opt_emit_signal == NULL)
{
+ /* don't keep repeatedly completing --signal */
if (request_completion)
- g_print ("--signal \n");
+ {
+ if (g_strcmp0 ("--signal", completion_prev) != 0)
+ g_print ("--signal \n");
+ }
else
- g_printerr (_("Error: Signal name is not specified\n"));
+ {
+ g_printerr (_("Error: Signal name is not specified\n"));
+ }
+
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);
goto out;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]