summaryrefslogtreecommitdiffhomepage
path: root/keysafe.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-09-04 12:30:39 -0400
committerJoey Hess <joeyh@joeyh.name>2016-09-04 12:30:39 -0400
commitc7dba730abf38e31d38dec1028d9844e0724e707 (patch)
tree386003db1f18f272a2bc95757f7b0f0cc581a9c9 /keysafe.hs
parent75cfb0df9467a2b07bb93e71ca55937839d53715 (diff)
downloadkeysafe-c7dba730abf38e31d38dec1028d9844e0724e707.tar.gz
Added --name and --othername options.
Diffstat (limited to 'keysafe.hs')
-rw-r--r--keysafe.hs48
1 files changed, 28 insertions, 20 deletions
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