From 6734397a53e2160257a89f8c391d89ea4aa02ad4 Mon Sep 17 00:00:00 2001 From: joe Date: Wed, 31 Aug 2016 23:33:04 -0400 Subject: Better error reporting --- kiki.hs | 72 +++++++++++++++++++++++++++-------------------------------------- 1 file changed, 30 insertions(+), 42 deletions(-) (limited to 'kiki.hs') diff --git a/kiki.hs b/kiki.hs index 9796c3d..adb7973 100644 --- a/kiki.hs +++ b/kiki.hs @@ -1179,6 +1179,32 @@ sync bExport bImport bSecret cmdarg args_raw = do putStrLn $ fname ++ ": " ++ reportString act +doTransform :: [String] -> ([String]->[Transform]) -> IO () +doTransform args mktrans = do + let (sargs,margs) = processArgs sargspec polyVariadicArgs "---" args + where sargspec = [] + polyVariadicArgs = ["---"] + passfd = fmap (FileDesc . read) passphrase_fd + where passphrase_fd = concat <$> Map.lookup "--passphrase-fd" margs + targs = fromMaybe [] $ Map.lookup "---" margs + homespec = join . take 1 <$> Map.lookup "--homedir" margs + kikiOp = KeyRingOperation + { opFiles = Map.fromList $ + [ ( HomeSec, buildStreamInfo KF_All KeyRingFile ) + , ( HomePub, buildStreamInfo KF_All KeyRingFile ) + ] + , opPassphrases = withAgent $ do pfile <- maybeToList passfd + return $ PassphraseSpec Nothing Nothing pfile + , opTransforms = mktrans targs + , opHome = homespec + } + KikiResult rt report <- runKeyRing kikiOp + forM_ report $ \(fname,act) -> do + putStrLn $ fname ++ ": " ++ reportString act + case rt of + KikiSuccess _ -> return () + err -> putStrLn $ errorString err + kiki :: String -> [String] -> IO () kiki "sync-secret" args_raw = sync True True True "sync-secret" args_raw @@ -1532,27 +1558,8 @@ kiki "delete" args | "--help" `elem` args = do , " with all associated signatures and trust markers." ] return () -kiki "delete" args = do - let (sargs,margs) = processArgs sargspec polyVariadicArgs "--delete" args - where sargspec = [] - polyVariadicArgs = ["--delete"] - passfd = fmap (FileDesc . read) passphrase_fd - where passphrase_fd = concat <$> Map.lookup "--passphrase-fd" margs - fps = fromMaybe [] $ Map.lookup "--delete" margs - homespec = join . take 1 <$> Map.lookup "--homedir" margs - kikiOp = KeyRingOperation - { opFiles = Map.fromList $ - [ ( HomeSec, buildStreamInfo KF_All KeyRingFile ) - , ( HomePub, buildStreamInfo KF_All KeyRingFile ) - ] - , opPassphrases = withAgent $ do pfile <- maybeToList passfd - return $ PassphraseSpec Nothing Nothing pfile - , opTransforms = map DeleteSubkeyByFingerprint fps - , opHome = homespec - } - KikiResult rt report <- runKeyRing kikiOp - forM_ report $ \(fname,act) -> do - putStrLn $ fname ++ ": " ++ reportString act +kiki "delete" args = doTransform args delete + where delete fps = map DeleteSubkeyByFingerprint fps kiki "rename" args | "--help" `elem` args = do putStr . unlines $ @@ -1562,28 +1569,9 @@ kiki "rename" args | "--help" `elem` args = do , " The old signature will be replaced and a new one formed." ] return () -kiki "rename" args = do - let (sargs,margs) = processArgs sargspec polyVariadicArgs "--rename" args - where sargspec = [("--homedir",1)] - polyVariadicArgs = ["--rename"] - passfd = fmap (FileDesc . read) passphrase_fd - where passphrase_fd = concat <$> Map.lookup "--passphrase-fd" margs - (oldtag:newtag:_) = fromMaybe [] $ Map.lookup "--rename" margs - homespec = join . take 1 <$> Map.lookup "--homedir" margs - kikiOp = KeyRingOperation - { opFiles = Map.fromList $ - [ ( HomeSec, buildStreamInfo KF_All KeyRingFile ) - , ( HomePub, buildStreamInfo KF_All KeyRingFile ) - ] - , opPassphrases = withAgent $ do pfile <- maybeToList passfd - return $ PassphraseSpec Nothing Nothing pfile - , opTransforms = [ RenameSubkeys oldtag newtag] - , opHome = homespec - } - KikiResult rt report <- runKeyRing kikiOp - forM_ report $ \(fname,act) -> do - putStrLn $ fname ++ ": " ++ reportString act +kiki "rename" args = doTransform args rename + where rename (oldtag:newtag:_) = [ RenameSubkeys oldtag newtag ] kiki "tar" args | "--help" `elem` args = do putStr . unlines $ -- cgit v1.2.3