mirror of
https://github.com/ilyakooo0/optparse-applicative.git
synced 2024-11-27 11:56:20 +03:00
Recover from compgen failures.
This commit is contained in:
parent
1820597c6b
commit
a3081f1a30
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user