1
0
mirror of https://github.com/redelmann/scat synced 2025-04-26 07:18:37 +02:00
scat/src/Scat/Options.hs
2013-08-14 17:11:13 +02:00

94 lines
2.4 KiB
Haskell

-- | Parses command-line arguments.
module Scat.Options
(
-- * Type
Options
-- * Accessors
, password
, service
, useCode
, code
, schema
, verbose
, confirm
, ansi
-- * Execution
, getOptions
) where
import Data.Monoid
import Options.Applicative
-- | All program options.
data Options = Options
{ password :: Maybe String
-- ^ Password, optionally provided.
, service :: Maybe String
-- ^ Service for which to generate the password.
, useCode :: Bool
-- ^ Indicates if extra code should be used.
, code :: Maybe String
-- ^ Extra code.
, schema :: String
-- ^ Name of the schema to use.
, verbose :: Bool
-- ^ Verbosity. If false, do not print anything but the generated password.
, confirm :: Bool
-- ^ Indicates if the password must be confirmed.
, ansi :: Bool
-- ^ Indicates if ANSI escape sequences can be used.
}
-- | Parses the arguments from the command line.
getOptions :: IO Options
getOptions = execParser opts
where
opts = info (helper <*> options)
(fullDesc
<> progDesc (unwords
[ "Safely generate passwords derived "
, "from a unique password and code." ])
<> header "scat - a password scatterer")
-- | Option parser.
options :: Parser Options
options = Options
<$> optional
(strOption (short 'p'
<> long "password"
<> help "The password"
<> metavar "PASSWORD"))
<*> optional (strOption
(short 'S'
<> long "service"
<> help "Service associated (website, email address, ...)"
<> metavar "SERVICE"))
<*> flag True False
(long "nocode"
<> help "Indicates that extra code should be not be used")
<*> optional
(strOption (short 'x'
<> long "code"
<> help "The extra code to use"
<> metavar "CODE"))
<*> strOption
(short 's'
<> long "schema"
<> help "Schema for the generated password"
<> metavar "SCHEMA"
<> value "safe"
<> showDefault)
<*> flag True False
(long "silent"
<> help "Do not print anything but the generated password")
<*> switch
(short 'c'
<> long "confirmation"
<> help "Asks for password confirmation")
<*> flag True False
(long "noansi"
<> help "Do not use ANSI escape sequences to format output")