module Data.QRCodes.Exe where
import Options.Applicative
import Data.Aeson
import qualified Data.ByteString as B
import System.Environment (getArgs)
import Data.QRCodes
import Data.Monoid
data Prog = Prog { cmd :: Com
, secured :: Bool
, verify :: Bool
, file :: String}
data Com = Input | Output
exec :: IO ()
exec = execParser full >>= act
where
full = info (helper <*> program)
( fullDesc
<> progDesc "Read/Write QR Codes with files"
<> header "qrpipe - QR utilities made in Haskell" )
act :: Prog -> IO ()
act (Prog Output True True filepath) = do
pipeIn <- getContents
createSecureQRCode pipeIn ".key.hk" filepath
(readQRStrSec filepath ".key.hk" :: IO String) >>= print
act (Prog Output False True filepath) = do
pipeIn <- B.getContents
byteStringToQR pipeIn filepath
readQRString filepath >>= print
act (Prog Output True False filepath) = do
pipeIn <- getContents
createSecureQRCode (pipeIn) ".key.hk" filepath
act (Prog Output False False filepath) = do
pipeIn <- B.getContents
byteStringToQR pipeIn filepath
act (Prog Input True _ filepath) =
(readQRStrSec filepath ".key.hk" :: IO String) >>= print
act (Prog Input False _ filepath) =
readQRString filepath >>= print
program :: Parser Prog
program = Prog
<$> subparser
( command "write" (info (pure Output)
( progDesc "Create a QR Code from stdin" ))
<> command "read" (info (pure Input)
( progDesc "Read a QR code from file" )))
<*> switch
( long "signed"
<> short 's'
<> help "Whether to sign the QR code" )
<*> switch
( long "verify"
<> short 'v'
<> help "Attempt to read the resultant file?" )
<*> argument str (metavar "FILE")