From 30e91608555839e3cb0113cdbd670e76d2d35508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 13 Apr 2025 10:57:56 +0200 Subject: Output style options Changelog: Added `--terminal-output` and `--log-output` options to set output style --- src/Main.hs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/Main.hs') diff --git a/src/Main.hs b/src/Main.hs index 1b062e8..49aa290 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -7,9 +7,11 @@ import Control.Monad.Reader import Data.ByteString.Lazy qualified as BL import Data.List import Data.List.NonEmpty qualified as NE +import Data.Maybe import Data.Proxy import Data.Text qualified as T +import System.Console.ANSI import System.Console.GetOpt import System.Directory import System.Environment @@ -22,8 +24,8 @@ import Command.Checkout import Command.JobId import Command.Run import Config +import Output import Repo -import Terminal import Version data CmdlineOptions = CmdlineOptions @@ -31,6 +33,7 @@ data CmdlineOptions = CmdlineOptions , optShowVersion :: Bool , optCommon :: CommonOptions , optStorage :: Maybe FilePath + , optOutput :: Maybe [ OutputType ] } defaultCmdlineOptions :: CmdlineOptions @@ -39,6 +42,7 @@ defaultCmdlineOptions = CmdlineOptions , optShowVersion = False , optCommon = defaultCommonOptions , optStorage = Nothing + , optOutput = Nothing } options :: [ OptDescr (CmdlineOptions -> Except String CmdlineOptions) ] @@ -66,6 +70,15 @@ options = , Option [] [ "storage" ] (ReqArg (\value opts -> return opts { optStorage = Just value }) "") "set storage path" + , Option [] [ "terminal-output" ] + (NoArg $ \opts -> return opts { optOutput = Just $ TerminalOutput : fromMaybe [] (optOutput opts) }) + "use terminal-style output (default if standard output is terminal)" + , Option [] [ "log-output" ] + (OptArg (\value opts -> return opts { optOutput = Just $ LogOutput (fromMaybe "-" value) : fromMaybe [] (optOutput opts) }) "") + "use log-style output to or standard output" + , Option [] [ "test-output" ] + (OptArg (\value opts -> return opts { optOutput = Just $ TestOutput (fromMaybe "-" value) : fromMaybe [] (optOutput opts) }) "") + "use test-style output to or standard output" ] data SomeCommandType = forall c. Command c => SC (Proxy c) @@ -241,5 +254,10 @@ runSomeCommand rootPath gopts (SC tproxy) args = do let ciOtherRepos = configRepos ++ cmdlineRepos - ciTerminalOutput <- initTerminalOutput - flip runReaderT CommandInput {..} exec + outputTypes <- case optOutput gopts of + Just types -> return types + Nothing -> hSupportsANSI stdout >>= return . \case + True -> [ TerminalOutput ] + False -> [ LogOutput "-" ] + withOutput outputTypes $ \ciOutput -> do + flip runReaderT CommandInput {..} exec -- cgit v1.2.3