{-# LANGUAGE OverloadedStrings #-}{- |Module : Hstratus.Cli.CommonSpecCopyright : (c) 2026 Tim EmiolaMaintainer : Tim Emiola <adetokunbo@emio.la>SPDX-License-Identifier: BSD-3-ClauseTests for the shared CLI options parser in 'Hstratus.Cli.Common'.-}module Hstratus.Cli.CommonSpec (spec) whereimport Hstratus.Cli.Common (commonOptsParser)import Network.HStratus.Http.Cli (CommonOpts (..))import Options.Applicative (ParserResult (..), defaultPrefs, execParserPure, fullDesc, info, renderFailure)import Test.Hspecimport Test.Hspec.Benri (endsRight)defaultOpts :: CommonOptsdefaultOpts = CommonOpts False False Nothing False Falsespec :: Specspec = describe "Hstratus.Cli.Common.commonOptsParser" $ do it "defaults all flags to False with no log file" $ pure (parseOpts []) `endsRight` defaultOpts it "sets optChina when --china is given" $ fmap optChina (parseOpts ["--china"]) `shouldBe` Right True it "sets optLog when --log is given" $ fmap optLog (parseOpts ["--log"]) `shouldBe` Right True it "sets optLogFile when --log-file is given" $ fmap optLogFile (parseOpts ["--log-file", "/tmp/test.log"]) `shouldBe` Right (Just "/tmp/test.log") it "sets optLogBodies when --log-bodies is given" $ fmap optLogBodies (parseOpts ["--log-bodies"]) `shouldBe` Right True it "sets optRedact when --redact is given" $ fmap optRedact (parseOpts ["--redact"]) `shouldBe` Right True it "accepts multiple flags together" $ pure (parseOpts ["--log", "--redact", "--china"]) `endsRight` defaultOpts{optChina = True, optLog = True, optRedact = True}parseOpts :: [String] -> Either String CommonOptsparseOpts args = case execParserPure defaultPrefs (info commonOptsParser fullDesc) args of Success opts -> Right opts Failure failure -> Left (fst (renderFailure failure "test")) CompletionInvoked _ -> Left "completion invoked"