I'm building a brainfuck compiler. The executable accepts two commands $ brainfuck compile ...
and $ brainfuck run
. I want the executable to auto complete when pressing tab. E.g. writing $ brainfuck com
and then pressing tab should generate $ brainfuck compile
.
data Command = Compile CompileArgs | Run RunArgs
deriving (Show)
main :: IO ()
main = execute =<< execParser opts
where
opts = info (helper <*> argsParser) fullDesc
execute :: Command -> IO ()
execute (Compile args) = compile args
execute (Run args) = run args
argsParser :: Parser Command
argsParser = subparser (compileCommand <> runCommand)
where
compileCommand = command "compile" $ info compileOptions $ progDesc "Compile brainfuck to an executable"
runCommand = command "run" $ info runOptions $ progDesc "Execute brainfuck code"
There is a section on optparse's github page here, but I don't really understand it.
The function completeWith :: Options.Applicative.Builder.Internal.HasCompleter f => [String] -> Mod f a
looks quite similar to command :: String -> ParserInfo a -> Mod CommandFields a
which I'm already using. So I figured I could use it and just combine them with <>
but it turns out that CommandFields
is not an instance of HasCompleter
.
How are you supposed to get the auto completion to work?