module GenHeader.Parsers (parseOptions) where import Cardano.Tools.Headers (Options (..)) import Data.Version (showVersion) import Options.Applicative ( Parser , ParserInfo , auto , command , execParser , help , helper , hsubparser , info , long , metavar , option , progDesc , short , (<**>) ) import Paths_ouroboros_consensus (version) parseOptions :: IO Options parseOptions :: IO Options parseOptions = ParserInfo Options -> IO Options forall a. ParserInfo a -> IO a execParser ParserInfo Options argsParser argsParser :: ParserInfo Options argsParser :: ParserInfo Options argsParser = Parser Options -> InfoMod Options -> ParserInfo Options forall a. Parser a -> InfoMod a -> ParserInfo a info (Parser Options optionsParser Parser Options -> Parser (Options -> Options) -> Parser Options forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b <**> Parser (Options -> Options) forall a. Parser (a -> a) helper) ( [Char] -> InfoMod Options forall a. [Char] -> InfoMod a progDesc ([Char] -> InfoMod Options) -> [Char] -> InfoMod Options forall a b. (a -> b) -> a -> b $ [[Char]] -> [Char] unlines [ [Char] "gen-header - A utility to generate valid and invalid Praos headers for testing purpose" , [Char] "version: " [Char] -> [Char] -> [Char] forall a. Semigroup a => a -> a -> a <> Version -> [Char] showVersion Version version ] ) optionsParser :: Parser Options optionsParser :: Parser Options optionsParser = Mod CommandFields Options -> Parser Options forall a. Mod CommandFields a -> Parser a hsubparser ( [Char] -> ParserInfo Options -> Mod CommandFields Options forall a. [Char] -> ParserInfo a -> Mod CommandFields a command [Char] "generate" ( Parser Options -> InfoMod Options -> ParserInfo Options forall a. Parser a -> InfoMod a -> ParserInfo a info Parser Options generateOptionsParser ( [Char] -> InfoMod Options forall a. [Char] -> InfoMod a progDesc [Char] "Generate Praos headers context and valid/invalid headers. Writes JSON formatted context to stdout and headers to stdout." ) ) Mod CommandFields Options -> Mod CommandFields Options -> Mod CommandFields Options forall a. Semigroup a => a -> a -> a <> [Char] -> ParserInfo Options -> Mod CommandFields Options forall a. [Char] -> ParserInfo a -> Mod CommandFields a command [Char] "validate" ( Parser Options -> InfoMod Options -> ParserInfo Options forall a. Parser a -> InfoMod a -> ParserInfo a info Parser Options validateOptionsParser ( [Char] -> InfoMod Options forall a. [Char] -> InfoMod a progDesc [Char] "Validate a sample of Praos headers within a context. Reads JSON formatted sample from stdin." ) ) ) validateOptionsParser :: Parser Options validateOptionsParser :: Parser Options validateOptionsParser = Options -> Parser Options forall a. a -> Parser a forall (f :: * -> *) a. Applicative f => a -> f a pure Options Validate generateOptionsParser :: Parser Options generateOptionsParser :: Parser Options generateOptionsParser = Int -> Options Generate (Int -> Options) -> Parser Int -> Parser Options forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> Parser Int countParser countParser :: Parser Int countParser :: Parser Int countParser = ReadM Int -> Mod OptionFields Int -> Parser Int forall a. ReadM a -> Mod OptionFields a -> Parser a option ReadM Int forall a. Read a => ReadM a auto ( [Char] -> Mod OptionFields Int forall (f :: * -> *) a. HasName f => [Char] -> Mod f a long [Char] "count" Mod OptionFields Int -> Mod OptionFields Int -> Mod OptionFields Int forall a. Semigroup a => a -> a -> a <> Char -> Mod OptionFields Int forall (f :: * -> *) a. HasName f => Char -> Mod f a short Char 'c' Mod OptionFields Int -> Mod OptionFields Int -> Mod OptionFields Int forall a. Semigroup a => a -> a -> a <> [Char] -> Mod OptionFields Int forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a metavar [Char] "INT" Mod OptionFields Int -> Mod OptionFields Int -> Mod OptionFields Int forall a. Semigroup a => a -> a -> a <> [Char] -> Mod OptionFields Int forall (f :: * -> *) a. [Char] -> Mod f a help [Char] "Number of headers to generate" )