diff --git a/src/Main.hs b/src/Main.hs index a091bbf..5d5a17b 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -32,15 +32,19 @@ fuzzy x = filter (any (isInfixOf x) . strings) -- Keychain access -- keychainList :: IO [FilePath] -keychainList = - runParser parseKeychainList <$> - readProcess "security" ["list-keychains"] "" +keychainList = do + raw <- readProcess "security" ["list-keychains"] "" + case runParser parseKeychainList raw of + Just list -> return list + Nothing -> error "failed to parse active keychains list" getKeychain :: IO Keychain getKeychain = do paths <- filter ((/="System") . takeBaseName) <$> keychainList - dump <- readProcess "security" ("dump-keychain" : "-d" : paths) "" - return (runParser parseKeychain dump) + raw <- readProcess "security" ("dump-keychain" : "-d" : paths) "" + case runParser parseKeychain raw of + Just items -> return items + Nothing -> error "failed to parse keychain" sendClipboard :: String -> IO () sendClipboard text = diff --git a/src/Parser.hs b/src/Parser.hs index b80d0c8..a76e996 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -14,11 +14,11 @@ import Data.Hex (unhex) import Data.Time -runParser :: Monoid a => Parser a -> String -> a +runParser :: Parser a -> String -> Maybe a runParser parser = handle . parseOnly parser . pack where - handle (Left _) = mempty - handle (Right x) = x + handle (Left _) = Nothing + handle (Right x) = Just x -- Parsers --