From c7dba730abf38e31d38dec1028d9844e0724e707 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 4 Sep 2016 12:30:39 -0400 Subject: Added --name and --othername options. --- keysafe.hs | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) (limited to 'keysafe.hs') diff --git a/keysafe.hs b/keysafe.hs index f78168b..569e678 100644 --- a/keysafe.hs +++ b/keysafe.hs @@ -53,15 +53,15 @@ dispatch cmdline ui storagelocations tunables possibletunables = do go mode (CmdLine.secretkeysource cmdline) where go CmdLine.Backup (Just secretkeysource) = - backup storagelocations ui tunables secretkeysource + backup cmdline storagelocations ui tunables secretkeysource =<< getSecretKey secretkeysource go CmdLine.Restore (Just secretkeydest) = - restore storagelocations ui possibletunables secretkeydest + restore cmdline storagelocations ui possibletunables secretkeydest go CmdLine.Backup Nothing = - backup storagelocations ui tunables Gpg.anyKey + backup cmdline storagelocations ui tunables Gpg.anyKey =<< Gpg.getKeyToBackup ui go CmdLine.Restore Nothing = - restore storagelocations ui possibletunables Gpg.anyKey + restore cmdline storagelocations ui possibletunables Gpg.anyKey go CmdLine.UploadQueued _ = uploadQueued (CmdLine.localstoragedirectory cmdline) go (CmdLine.Server) _ = @@ -74,19 +74,23 @@ dispatch cmdline ui storagelocations tunables possibletunables = do go CmdLine.Test _ = runTests -backup :: StorageLocations -> UI -> Tunables -> SecretKeySource -> SecretKey -> IO () -backup storagelocations ui tunables secretkeysource secretkey = do +backup :: CmdLine.CmdLine -> StorageLocations -> UI -> Tunables -> SecretKeySource -> SecretKey -> IO () +backup cmdline storagelocations ui tunables secretkeysource secretkey = do username <- userName - Name theirname <- fromMaybe (error "Aborting on no username") - <$> promptName ui "Enter your name" - usernamedesc (Just username) validateName + Name theirname <- case CmdLine.name cmdline of + Just n -> pure n + Nothing -> fromMaybe (error "Aborting on no username") + <$> promptName ui "Enter your name" + usernamedesc (Just username) validateName go theirname where go theirname = do cores <- fromMaybe 1 <$> getNumCores - Name othername <- fromMaybe (error "aborting on no othername") - <$> promptName ui "Enter other name" - othernamedesc Nothing validateName + Name othername <- case CmdLine.name cmdline of + Just n -> pure n + Nothing -> fromMaybe (error "aborting on no othername") + <$> promptName ui "Enter other name" + othernamedesc Nothing validateName let name = Name (theirname <> " " <> othername) kek <- promptkek name let sis = shareIdents tunables name secretkeysource @@ -184,16 +188,20 @@ otherNameSuggestions = unlines $ map (" * " ++) , "A place you like to visit." ] -restore :: StorageLocations -> UI -> [Tunables] -> SecretKeySource -> IO () -restore storagelocations ui possibletunables secretkeydest = do +restore :: CmdLine.CmdLine -> StorageLocations -> UI -> [Tunables] -> SecretKeySource -> IO () +restore cmdline storagelocations ui possibletunables secretkeydest = do cores <- fromMaybe 1 <$> getNumCores username <- userName - Name theirname <- fromMaybe (error "Aborting on no username") - <$> promptName ui "Enter your name" - namedesc (Just username) validateName - Name othername <- fromMaybe (error "aborting on no othername") - <$> promptName ui "Enter other name" - othernamedesc Nothing validateName + Name theirname <- case CmdLine.name cmdline of + Just n -> pure n + Nothing -> fromMaybe (error "Aborting on no username") + <$> promptName ui "Enter your name" + namedesc (Just username) validateName + Name othername <- case CmdLine.name cmdline of + Just n -> pure n + Nothing -> fromMaybe (error "aborting on no othername") + <$> promptName ui "Enter other name" + othernamedesc Nothing validateName let name = Name (theirname <> " " <> othername) password <- fromMaybe (error "Aborting on no password") <$> promptPassword ui True "Enter password" passworddesc -- cgit v1.2.3