blob: 8e3040ad7b06a7e46b96540fd072ec7c3550a622 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
{- 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
, keytype :: KeyType
, testMode :: Bool
, gui :: Bool
}
deriving (Show)
data Mode = Backup | Restore | Benchmark
deriving (Show)
parse :: Parser CmdLine
parse = CmdLine
<$> (backup <|> restore <|> benchmark)
<*> keytypeopt
<*> testmodeswitch
<*> guiswitch
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."
)
benchmark = flag' Benchmark
( long "benchmark"
<> help "Benchmark speed of keysafe's cryptographic primitives."
)
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."
)
guiswitch = switch
( long "gui"
<> help "Use GUI interface for interaction. Default is to use readline interface when run in a terminal, and GUI otherwise."
)
get :: IO CmdLine
get = execParser opts
where
opts = info (helper <*> parse)
( fullDesc
<> header "keysafe - securely back up secret keys"
)
|