summaryrefslogtreecommitdiffhomepage
path: root/CmdLine.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-08-12 01:04:06 -0400
committerJoey Hess <joeyh@joeyh.name>2016-08-12 01:04:06 -0400
commitf74151ead49895f86257c9abfbe90c027d91d456 (patch)
treeb3be9d579348c953d3348de3715eef95b8680d50 /CmdLine.hs
parentad93e84990f4205182a2ae68ec2ad485af4b4da4 (diff)
downloadkeysafe-f74151ead49895f86257c9abfbe90c027d91d456.tar.gz
option parsing
Diffstat (limited to 'CmdLine.hs')
-rw-r--r--CmdLine.hs57
1 files changed, 57 insertions, 0 deletions
diff --git a/CmdLine.hs b/CmdLine.hs
new file mode 100644
index 0000000..3d45d5a
--- /dev/null
+++ b/CmdLine.hs
@@ -0,0 +1,57 @@
+{- Copyright 2016 Joey Hess <id@joeyh.name>
+ -
+ - Licensed under the GNU AGPL version 3 or higher.
+ -}
+
+module CmdLine (CmdLine(..), Mode(..), get, parse) where
+
+import Types
+import Options.Applicative
+import qualified Data.ByteString.UTF8 as BU8
+
+data CmdLine = CmdLine
+ { mode :: Mode
+ , name :: Name
+ , keytype :: KeyType
+ , testMode :: Bool
+ }
+ deriving (Show)
+
+data Mode = Backup | Restore
+ deriving (Show)
+
+parse :: Parser CmdLine
+parse = CmdLine
+ <$> (backup <|> restore)
+ <*> nameopt
+ <*> keytypeopt
+ <*> testmodeswitch
+ where
+ backup = flag' Backup
+ ( long "backup"
+ <> help "Store a secret key in keysafe."
+ )
+ restore = flag' Restore
+ ( long "restore"
+ <> help "Retrieve a secret key from keysafe."
+ )
+ nameopt = Name . BU8.fromString <$> strOption
+ ( long "name"
+ <> help "Some name that is associated with the key. Should be something you can remember when restoring it."
+ )
+ keytypeopt = KeyType . BU8.fromString <$> strOption
+ ( long "type"
+ <> help "Type of key (eg, \"gpg\")."
+ )
+ testmodeswitch = switch
+ ( long "testmode"
+ <> help "Avoid using expensive cryptographic operation to secure key. Use for testing only, not with real secret keys."
+ )
+
+get :: IO CmdLine
+get = execParser opts
+ where
+ opts = info (helper <*> parse)
+ ( fullDesc
+ <> header "keysafe - securely back up secret keys"
+ )