{- Copyright 2016 Joey Hess - - 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 deriving (Show) parse :: Parser CmdLine parse = CmdLine <$> (backup <|> restore) <*> 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." ) 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" )