tool: add "address" command to print D-Bus address
authorDaiki Ueno <ueno@unixuser.org>
Fri, 2 Aug 2013 08:33:21 +0000 (10:33 +0200)
committerDaiki Ueno <ueno@unixuser.org>
Fri, 2 Aug 2013 08:33:21 +0000 (10:33 +0200)
This would be helpful to debug with dbus-monitor.  Instead of:

  $ . .config/ibus/bus/*
  $ dbus-monitor --address $IBUS_ADDRESS ...

one can do:

  $ dbus-monitor --address $(ibus address) ...

This patch also adds help message to each sub-command.

BUG=

Review URL: https://codereview.appspot.com/11901044

tools/ibus.1.in
tools/main.vala

index 80fcf41..ab99db4 100644 (file)
@@ -76,8 +76,14 @@ Save the custom registry cache
 if
 .B \-\-file=FILE
 is given.
-IBUS_COMPONENT_PATH environment valuable is also available for
-the custom component directories, whose delimiter is ':'.
+
+By default, it reads the component XML files from the standard
+component directory (\fI/usr/share/ibus/component\fP), you can set
+\fIIBUS_COMPONENT_PATH\fP environment variable for custom component
+directories, separated by ':'.
+.TP
+\fBaddress\fR
+Show the D-Bus address of ibus-daemon.
 .TP
 \fBwatch\fR
 Under construction.
index f3959af..4595e21 100644 (file)
@@ -270,6 +270,11 @@ int write_cache (string[] argv) {
             Posix.EXIT_SUCCESS : Posix.EXIT_FAILURE;
 }
 
+int print_address(string[] argv) {
+    print("%s\n", IBus.get_address());
+    return Posix.EXIT_SUCCESS;
+}
+
 int print_help(string[] argv) {
     print_usage(stdout);
     return Posix.EXIT_SUCCESS;
@@ -278,20 +283,22 @@ int print_help(string[] argv) {
 delegate int EntryFunc(string[] argv);
 
 struct CommandEntry {
-    string name;
-    EntryFunc entry;
+    unowned string name;
+    unowned string description;
+    unowned EntryFunc entry;
 }
 
 static const CommandEntry commands[]  = {
-    { "engine", get_set_engine },
-    { "exit", exit_daemon },
-    { "list-engine", list_engine },
-    { "watch", message_watch },
-    { "restart", restart_daemon },
-    { "version", print_version },
-    { "read-cache", read_cache },
-    { "write-cache", write_cache },
-    { "help", print_help }
+    { "engine", N_("Set or get engine"), get_set_engine },
+    { "exit", N_("Exit ibus-daemon"), exit_daemon },
+    { "list-engine", N_("Show available engines"), list_engine },
+    { "watch", N_("(Not implemented)"), message_watch },
+    { "restart", N_("Restart ibus-daemon"), restart_daemon },
+    { "version", N_("Show version"), print_version },
+    { "read-cache", N_("Show the content of registry cache"), read_cache },
+    { "write-cache", N_("Create registry cache"), write_cache },
+    { "address", N_("Print the D-Bus address of ibus-daemon"), print_address },
+    { "help", N_("Show this information"), print_help }
 };
 
 static string program_name;
@@ -300,14 +307,17 @@ void print_usage(FileStream stream) {
     stream.printf(_("Usage: %s COMMAND [OPTION...]\n\n"), program_name);
     stream.printf(_("Commands:\n"));
     for (int i = 0; i < commands.length; i++) {
-        stream.printf("  %s\n", commands[i].name);
+        stream.printf("  %-11s    %s\n",
+                      commands[i].name,
+                      GLib.dgettext(null, commands[i].description));
     }
 }
 
 public int main(string[] argv) {
     GLib.Intl.setlocale(GLib.LocaleCategory.ALL, "");
-    GLib.Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.GLIB_LOCALE_DIR);
-    GLib.Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
+    GLib.Intl.bindtextdomain(Config.GETTEXT_PACKAGE, Config.GLIB_LOCALE_DIR);
+    GLib.Intl.bind_textdomain_codeset(Config.GETTEXT_PACKAGE, "UTF-8");
+    GLib.Intl.textdomain(Config.GETTEXT_PACKAGE);
 
     IBus.init();