packages feed

kiroku-cli-0.2.0.10 / src / Kiroku / Cli / Parser.hs

module Kiroku.Cli.Parser (    kirokuCommandParser,    kirokuParserInfo,    kirokuSubparser,) whereimport Control.Applicative (optional)import Data.Text qualified as Timport Kiroku.Cli.Command (KirokuCommand (..))import Kiroku.Cli.Command qualified as Commandimport Options.Applicative (    CommandFields,    Mod,    Parser,    ParserInfo,    command,    eitherReader,    fullDesc,    header,    help,    helper,    info,    long,    metavar,    option,    progDesc,    strOption,    subparser,    value,    (<**>), )kirokuCommandParser :: Parser KirokuCommandkirokuCommandParser =    maybe KirokuNoCommand id        <$> optional            ( subparser                ( command                    "subscriptions"                    ( info                        (KirokuSubscriptions <$> subscriptionCommandParser)                        (fullDesc <> progDesc "Inspect live subscriptions in this process's KirokuStore registry.")                    )                )            )subscriptionCommandParser :: Parser Command.SubscriptionCommandsubscriptionCommandParser =    subparser        ( command            "status"            ( info                (Command.SubscriptionStatus <$> statusOptionsParser <**> helper)                (fullDesc <> progDesc "List live subscription phases and global cursor positions.")            )        )statusOptionsParser :: Parser Command.StatusOptionsstatusOptionsParser =    Command.StatusOptions        <$> option            (eitherReader parseOutputFormat)            ( long "format"                <> metavar "table|json"                <> value Command.OutputTable                <> help "Render as a human table or script-friendly JSON."            )        <*> optional            ( Command.RemoteEndpoint . T.pack                <$> strOption                    ( long "remote-url"                        <> metavar "URL"                        <> help                            "Query a running worker's kiroku-metrics /subscriptions endpoint \                            \(e.g. http://worker:9091) instead of this process's local registry."                    )            )parseOutputFormat :: String -> Either String Command.OutputFormatparseOutputFormat "table" = Right Command.OutputTableparseOutputFormat "json" = Right Command.OutputJsonparseOutputFormat other = Left ("unsupported output format " <> show other <> "; expected table or json")kirokuParserInfo :: ParserInfo KirokuCommandkirokuParserInfo =    info        (kirokuCommandParser <**> helper)        ( fullDesc            <> progDesc "Run Kiroku operator commands."            <> header "kiroku - operator commands for Kiroku event stores"        )kirokuSubparser :: (KirokuCommand -> command) -> Mod CommandFields commandkirokuSubparser wrap =    command        "kiroku"        ( info            (wrap <$> kirokuCommandParser <**> helper)            ( fullDesc                <> progDesc "Run Kiroku operator commands."            )        )