Fix a bug in the generation of completion information
authorMichele Tartara <mtartara@google.com>
Tue, 8 Jan 2013 08:49:08 +0000 (08:49 +0000)
committerMichele Tartara <mtartara@google.com>
Tue, 8 Jan 2013 09:26:18 +0000 (10:26 +0100)
Completion information for multi-command binaries were not generated in
the correct way, so the build-bash-complation script failed when such a
binary was actually found.

This commit fixes this issue, and a related docstring typo as well.

Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

src/Ganeti/Common.hs

index cf80caa..75dca4b 100644 (file)
@@ -117,7 +117,7 @@ complToText compl =
       stripped = stripPrefix "OptCompl" show_compl
   in map toLower $ fromMaybe show_compl stripped
 
--- | Tex serialisation for 'ArgCompletion'.
+-- | Text serialisation for 'ArgCompletion'.
 argComplToText :: ArgCompletion -> String
 argComplToText (ArgCompletion optc min_cnt max_cnt) =
   complToText optc ++ " " ++ show min_cnt ++ " " ++ maybe "none" show max_cnt
@@ -236,15 +236,14 @@ showCmdUsage prog personalities success = do
 -- | Generates completion information for a multi-command binary.
 multiCmdCompletion :: (StandardOptions a) => PersonalityList a -> String
 multiCmdCompletion personalities =
-  unlines .
-  map argComplToText $
-  map (\(cmd, _) -> ArgCompletion (OptComplChoices [cmd]) 1 (Just 1))
-    personalities
+  argComplToText $
+    ArgCompletion (OptComplChoices (map fst personalities))
+      1 (Just 1)
 
 -- | Displays completion information for a multi-command binary and exits.
 showCmdCompletion :: (StandardOptions a) => PersonalityList a -> IO b
 showCmdCompletion personalities =
-  putStr (multiCmdCompletion personalities) >> exitSuccess
+  putStrLn (multiCmdCompletion personalities) >> exitSuccess
 
 -- | Command line parser, using a generic 'Options' structure.
 parseOpts :: (StandardOptions a) =>