{-# LANGUAGE FlexibleContexts, OverloadedStrings, RecordWildCards #-}

-- | Command-line interface for generating AWS CloudFront signed cookies.
--
-- This program is the aggregation of these subcommands:
--
-- * "Network.AWS.CloudFront.SignedCookies.CLI.Decode"
-- * "Network.AWS.CloudFront.SignedCookies.CLI.Sign"

module Network.AWS.CloudFront.SignedCookies.CLI
  ( main
  ) where

import Network.AWS.CloudFront.SignedCookies.CLI.Internal

import qualified Network.AWS.CloudFront.SignedCookies.CLI.Decode as Decode
import qualified Network.AWS.CloudFront.SignedCookies.CLI.Sign   as Sign

-- base
import Control.Monad (join)
import Data.Semigroup ((<>))

-- optparse-applicative
import qualified Options.Applicative as Opt

-- | Entry point for the AWS CloudFront signed cookie command-line interface.

main :: IO ()
main :: IO ()
main =
  IO (IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (IO (IO ()) -> IO ()) -> IO (IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ ParserInfo (IO ()) -> IO (IO ())
forall a. ParserInfo a -> IO a
Opt.execParser ParserInfo (IO ())
mainParserInfo

mainParserInfo :: Opt.ParserInfo (IO ())
mainParserInfo :: ParserInfo (IO ())
mainParserInfo =
  Parser (IO ()) -> InfoMod (IO ()) -> ParserInfo (IO ())
forall a. Parser a -> InfoMod a -> ParserInfo a
Opt.info (Parser (IO () -> IO ())
forall a. Parser (a -> a)
Opt.helper Parser (IO () -> IO ()) -> Parser (IO ()) -> Parser (IO ())
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser (IO ())
mainParser) (InfoMod (IO ()) -> ParserInfo (IO ()))
-> InfoMod (IO ()) -> ParserInfo (IO ())
forall a b. (a -> b) -> a -> b
$
    String -> InfoMod (IO ())
forall a. String -> InfoMod a
Opt.header String
"AWS CloudFront signed cookie utility"

mainParser :: Opt.Parser (IO ())
mainParser :: Parser (IO ())
mainParser =
  Mod CommandFields (IO ()) -> Parser (IO ())
forall a. Mod CommandFields a -> Parser a
Opt.hsubparser (Mod CommandFields (IO ()) -> Parser (IO ()))
-> Mod CommandFields (IO ()) -> Parser (IO ())
forall a b. (a -> b) -> a -> b
$
    String -> ParserInfo (IO ()) -> Mod CommandFields (IO ())
forall a. String -> ParserInfo a -> Mod CommandFields a
Opt.command String
"decode" ParserInfo (IO ())
Decode.mainParserInfo Mod CommandFields (IO ())
-> Mod CommandFields (IO ()) -> Mod CommandFields (IO ())
forall a. Semigroup a => a -> a -> a
<>
    String -> ParserInfo (IO ()) -> Mod CommandFields (IO ())
forall a. String -> ParserInfo a -> Mod CommandFields a
Opt.command String
"sign"   ParserInfo (IO ())
Sign.mainParserInfo