Commit daf0de68 authored by Iustin Pop's avatar Iustin Pop
Browse files

Implement fake completion support for multi-cmd binaries

This will allow build-bash-completion to understand what is the list
of commands that each binary supports, and then provide recursively
completion support for each command.

Note: by "fake", I mean we use hand-built output and hardcoded
"--help-completion" matching, as opposed to automatically doing it via
regular options. It could be possible in the future to use a
two-staged command line parser, but for now not sure if it's worth it.
Signed-off-by: default avatarIustin Pop <>
Reviewed-by: default avatarMichele Tartara <>
parent e892cdfa
......@@ -228,6 +228,19 @@ showCmdUsage prog personalities success = do
then exitSuccess
else exitWith $ ExitFailure C.exitFailure
-- | 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))
-- | Displays completion information for a multi-command binary and exits.
showCmdCompletion :: (StandardOptions a) => PersonalityList a -> IO b
showCmdCompletion personalities =
putStr (multiCmdCompletion personalities) >> exitSuccess
-- | Command line parser, using a generic 'Options' structure.
parseOpts :: (StandardOptions a) =>
a -- ^ The default options
......@@ -260,6 +273,7 @@ parseOptsCmds defaults argv progname personalities genopts = do
-- hardcoded option strings here!
"--version" -> putStrLn (versionInfo progname) >> exitSuccess
"--help" -> usage True
"--help-completion" -> showCmdCompletion personalities
_ -> return c
(cmd, cmd_args) <- case argv of
cmd:cmd_args -> do
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment