Recover from compgen failures.

This commit is contained in:
Paolo Capriotti 2012-08-02 20:25:18 +01:00
parent 1820597c6b
commit a3081f1a30

View File

@ -7,6 +7,7 @@ module Options.Applicative.Builder.Completer
) where
import Control.Applicative
import Control.Exception (IOException, try)
import Control.Monad
import Data.List
import Options.Applicative.Types
@ -32,5 +33,9 @@ dirCompleter = listIOCompleter $ do
bashCompleter :: String -> Completer
bashCompleter action = Completer $ \word -> do
let cmd = unwords ["compgen", "-A", action, word]
result <- readProcess "bash" ["-c", cmd] ""
return $ lines result
result <- tryIO $ readProcess "bash" ["-c", cmd] ""
return . lines . either (const []) id $ result
tryIO :: IO a -> IO (Either IOException a)
tryIO = try