From f8d011580abb35e3c37f1941d8edf64e5036816c Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Fri, 5 Oct 2012 22:17:54 +0200
Subject: [PATCH] Enable bash completion for Haskell daemons too

This requires a few tiny changes to build-bash-completion and to
Makefile rules, but is straightforward.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 Makefile.am                     |  2 +-
 autotools/build-bash-completion | 15 ++++++++++-----
 autotools/run-in-tempdir        |  2 +-
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 258f23aef..244b232c2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -182,7 +182,7 @@ HTOOLS_GENERATED_FILES =
 if WANT_HTOOLS
 HTOOLS_GENERATED_FILES += $(HS_PROGS)
 if ENABLE_CONFD
-HTOOLS_GENERATED_FILES += htools/hconfd
+HTOOLS_GENERATED_FILES += htools/hconfd htools/ganeti-confd
 endif
 endif
 
diff --git a/autotools/build-bash-completion b/autotools/build-bash-completion
index 816652c32..0dd77b02d 100755
--- a/autotools/build-bash-completion
+++ b/autotools/build-bash-completion
@@ -27,6 +27,7 @@
 # [C0103] Invalid name build-bash-completion
 
 import os
+import os.path
 import re
 import itertools
 import optparse
@@ -641,7 +642,7 @@ def HaskellOptToOptParse(opts, kind):
   opts = opts.split(",")
   if kind == "none":
     return cli.cli_option(*opts, action="store_true")
-  elif kind in ["file", "string", "host", "dir"]:
+  elif kind in ["file", "string", "host", "dir", "inetaddr"]:
     return cli.cli_option(*opts, type="string")
   elif kind == "numeric":
     # FIXME: float values here
@@ -718,11 +719,10 @@ def WriteHaskellCompletion(sw, script, htools=True, debug=True):
     script_name = script
     func_name = "htools_%s" % script
   else:
-    # note: this is not yet used (daemons)
-    cmd = script
+    cmd = "./" + script
     env = {}
-    script_name = script
-    func_name = script
+    script_name = os.path.basename(script)
+    func_name = script_name
   output = utils.RunCmd([cmd, "--help-completion"], env=env, cwd=".").output
   cli_opts = []
   args = []
@@ -786,6 +786,11 @@ def main():
       WriteHaskellCompletion(sw, script, htools=True,
                              debug=not options.compact)
 
+  # ganeti-confd, if enabled
+  if _autoconf.ENABLE_CONFD:
+    WriteHaskellCompletion(sw, "htools/ganeti-confd", htools=False,
+                           debug=not options.compact)
+
   # Reset extglob to original value
   sw.Write("[[ -n \"$gnt_shopt_extglob\" ]] && $gnt_shopt_extglob")
   sw.Write("unset gnt_shopt_extglob")
diff --git a/autotools/run-in-tempdir b/autotools/run-in-tempdir
index 15fa64c21..b23e42b3d 100755
--- a/autotools/run-in-tempdir
+++ b/autotools/run-in-tempdir
@@ -17,7 +17,7 @@ mv $tmpdir/lib $tmpdir/ganeti
 ln -T -s $tmpdir/ganeti $tmpdir/lib
 
 mkdir -p $tmpdir/htools $tmpdir/htest
-for hfile in htools; do
+for hfile in htools ganeti-confd; do
   if [ -e htools/$hfile ]; then
     cp -p htools/$hfile $tmpdir/htools/
   fi
-- 
GitLab