{-# LANGUAGE OverloadedLists #-}
module Shrun.Configuration.Args.Parsing.Notify
( notifyParser,
)
where
import Options.Applicative (Parser)
import Options.Applicative qualified as OA
import Shrun.Configuration.Args.Parsing.Utils qualified as Utils
import Shrun.Configuration.Data.Notify
( NotifyActionsInit (MkNotifyActionsInit, complete, start),
NotifyArgs,
NotifyP (MkNotifyP, actions, system, timeout),
)
import Shrun.Configuration.Data.Notify.Action
( NotifyActionComplete,
NotifyActionStartSwitch (MkNotifyActionStartSwitch),
)
import Shrun.Configuration.Data.Notify.Action qualified as Action
import Shrun.Configuration.Data.Notify.System qualified as System
import Shrun.Configuration.Data.Notify.Timeout qualified as Timeout
import Shrun.Configuration.Data.WithDisabled (WithDisabled)
import Shrun.Prelude
import Shrun.Utils qualified as ShrunUtils
notifyParser :: Parser (NotifyArgs r)
notifyParser :: forall r. Parser (NotifyArgs r)
notifyParser = do
Maybe (WithDisabled NotifyActionComplete)
complete <- Parser (Maybe (WithDisabled NotifyActionComplete))
notifyActionCompleteParser
Maybe NotifyActionStartSwitch
start <- Parser (Maybe NotifyActionStartSwitch)
notifyActionStartParser
Maybe NotifySystem
system <- Parser (Maybe NotifySystem)
notifySystemParser
Maybe NotifyTimeout
timeout <- Parser (Maybe NotifyTimeout)
notifyTimeoutParser
pure
$ MkNotifyP
{ actions :: NotifyActionsF 'ConfigPhaseArgs
actions =
MkNotifyActionsInit
{ Maybe (WithDisabled NotifyActionComplete)
NotifyActionCompleteF 'ConfigPhaseArgs
complete :: NotifyActionCompleteF 'ConfigPhaseArgs
complete :: Maybe (WithDisabled NotifyActionComplete)
complete,
Maybe NotifyActionStartSwitch
SwitchF 'ConfigPhaseArgs NotifyActionStartSwitch
start :: SwitchF 'ConfigPhaseArgs NotifyActionStartSwitch
start :: Maybe NotifyActionStartSwitch
start
},
Maybe NotifySystem
NotifySystemF 'ConfigPhaseArgs r
system :: NotifySystemF 'ConfigPhaseArgs r
system :: Maybe NotifySystem
system,
Maybe NotifyTimeout
ConfigPhaseF 'ConfigPhaseArgs NotifyTimeout
timeout :: ConfigPhaseF 'ConfigPhaseArgs NotifyTimeout
timeout :: Maybe NotifyTimeout
timeout
}
notifyActionCompleteParser :: Parser (Maybe (WithDisabled NotifyActionComplete))
notifyActionCompleteParser :: Parser (Maybe (WithDisabled NotifyActionComplete))
notifyActionCompleteParser =
ReadM NotifyActionComplete
-> [Mod OptionFields (WithDisabled NotifyActionComplete)]
-> (Bool, [String])
-> Parser (Maybe (WithDisabled NotifyActionComplete))
forall a.
ReadM a
-> [Mod OptionFields (WithDisabled a)]
-> (Bool, [String])
-> Parser (Maybe (WithDisabled a))
Utils.mWithDisabledParser
(ReadM Text
forall s. IsString s => ReadM s
OA.str ReadM Text
-> (Text -> ReadM NotifyActionComplete)
-> ReadM NotifyActionComplete
forall a b. ReadM a -> (a -> ReadM b) -> ReadM b
forall (m :: Type -> Type) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> ReadM NotifyActionComplete
forall (m :: Type -> Type).
MonadFail m =>
Text -> m NotifyActionComplete
Action.parseNotifyAction)
[Mod OptionFields (WithDisabled NotifyActionComplete)]
opts
(Bool, [String])
forall a. IsString a => (Bool, [a])
Action.notifyActionMeta
where
opts :: [Mod OptionFields (WithDisabled NotifyActionComplete)]
opts =
[ String -> Mod OptionFields (WithDisabled NotifyActionComplete)
forall (f :: Type -> Type) a. HasName f => String -> Mod f a
OA.long String
"notify-action-complete",
[String] -> Mod OptionFields (WithDisabled NotifyActionComplete)
forall (f :: Type -> Type) a. HasCompleter f => [String] -> Mod f a
OA.completeWith [String
Item [String]
"final", String
Item [String]
"command", String
Item [String]
"all"],
Item [Mod OptionFields (WithDisabled NotifyActionComplete)]
Mod OptionFields (WithDisabled NotifyActionComplete)
helpTxt
]
helpTxt :: Mod OptionFields (WithDisabled NotifyActionComplete)
helpTxt =
NESeq String
-> Mod OptionFields (WithDisabled NotifyActionComplete)
forall a. NESeq String -> Mod OptionFields a
Utils.itemize
(NESeq String
-> Mod OptionFields (WithDisabled NotifyActionComplete))
-> NESeq String
-> Mod OptionFields (WithDisabled NotifyActionComplete)
forall a b. (a -> b) -> a -> b
$ String
intro
String -> Seq String -> NESeq String
forall a. a -> Seq a -> NESeq a
:<|| [ String
Item (Seq String)
hall,
String
Item (Seq String)
hcommand,
String
Item (Seq String)
hfinal
]
intro :: String
intro = String
"Sends notifications for various 'complete' actions."
hfinal :: String
hfinal = String
"final: Sends off a single notification when shrun itself finishes."
hcommand :: String
hcommand = String
"command: Sends off a notification for each command that finishes."
hall :: String
hall = String
"all: Implies 'final' and 'command'."
notifyActionStartParser :: Parser (Maybe NotifyActionStartSwitch)
notifyActionStartParser :: Parser (Maybe NotifyActionStartSwitch)
notifyActionStartParser = (Bool -> NotifyActionStartSwitch)
-> String -> String -> Parser (Maybe NotifyActionStartSwitch)
forall a. (Bool -> a) -> String -> String -> Parser (Maybe a)
Utils.switchParser Bool -> NotifyActionStartSwitch
MkNotifyActionStartSwitch String
"notify-action-start" String
helpTxt
where
helpTxt :: String
helpTxt = String
"Sends a notification when a command is started."
notifySystemParser :: Parser (Maybe NotifySystem)
notifySystemParser :: Parser (Maybe NotifySystem)
notifySystemParser = Parser (Maybe NotifySystem)
mainParser
where
mainParser :: Parser (Maybe NotifySystem)
mainParser =
Parser NotifySystem -> Parser (Maybe NotifySystem)
forall (f :: Type -> Type) a. Alternative f => f a -> f (Maybe a)
OA.optional
(Parser NotifySystem -> Parser (Maybe NotifySystem))
-> Parser NotifySystem -> Parser (Maybe NotifySystem)
forall a b. (a -> b) -> a -> b
$ ReadM NotifySystem
-> Mod OptionFields NotifySystem -> Parser NotifySystem
forall a. ReadM a -> Mod OptionFields a -> Parser a
OA.option (ReadM Text -> ReadM NotifySystem
forall (m :: Type -> Type). MonadFail m => m Text -> m NotifySystem
System.parseNotifySystem ReadM Text
forall s. IsString s => ReadM s
OA.str)
(Mod OptionFields NotifySystem -> Parser NotifySystem)
-> Mod OptionFields NotifySystem -> Parser NotifySystem
forall a b. (a -> b) -> a -> b
$ [Mod OptionFields NotifySystem] -> Mod OptionFields NotifySystem
forall a. Monoid a => [a] -> a
mconcat
[ String -> Mod OptionFields NotifySystem
forall (f :: Type -> Type) a. HasName f => String -> Mod f a
OA.long String
"notify-system",
[String] -> Mod OptionFields NotifySystem
forall (f :: Type -> Type) a. HasCompleter f => [String] -> Mod f a
OA.completeWith [String
Item [String]
"dbus", String
Item [String]
"notify-send", String
Item [String]
"apple-script"],
String -> Mod OptionFields NotifySystem
forall (f :: Type -> Type) a. String -> Mod f a
Utils.mkHelp String
helpTxt,
String -> Mod OptionFields NotifySystem
forall (f :: Type -> Type) a. HasMetavar f => String -> Mod f a
OA.metavar ((Bool, [String]) -> String
forall a. (IsString a, Monoid a) => (Bool, [a]) -> a
ShrunUtils.mkMetaStr (Bool, [String])
forall a. IsString a => (Bool, [a])
System.notifySystemMeta)
]
helpTxt :: String
helpTxt =
[String] -> String
forall a. Monoid a => [a] -> a
mconcat
[ String
Item [String]
"The system used for sending notifications. 'dbus' and 'notify-send' ",
String
Item [String]
"are available on linux, whereas 'apple-script' is available for osx."
]
notifyTimeoutParser :: Parser (Maybe NotifyTimeout)
notifyTimeoutParser :: Parser (Maybe NotifyTimeout)
notifyTimeoutParser = Parser (Maybe NotifyTimeout)
mainParser
where
mainParser :: Parser (Maybe NotifyTimeout)
mainParser =
Parser NotifyTimeout -> Parser (Maybe NotifyTimeout)
forall (f :: Type -> Type) a. Alternative f => f a -> f (Maybe a)
OA.optional
(Parser NotifyTimeout -> Parser (Maybe NotifyTimeout))
-> Parser NotifyTimeout -> Parser (Maybe NotifyTimeout)
forall a b. (a -> b) -> a -> b
$ ReadM NotifyTimeout
-> Mod OptionFields NotifyTimeout -> Parser NotifyTimeout
forall a. ReadM a -> Mod OptionFields a -> Parser a
OA.option (ReadM Text -> ReadM NotifyTimeout
forall (m :: Type -> Type).
MonadFail m =>
m Text -> m NotifyTimeout
Timeout.parseNotifyTimeout ReadM Text
forall s. IsString s => ReadM s
OA.str)
(Mod OptionFields NotifyTimeout -> Parser NotifyTimeout)
-> Mod OptionFields NotifyTimeout -> Parser NotifyTimeout
forall a b. (a -> b) -> a -> b
$ [Mod OptionFields NotifyTimeout] -> Mod OptionFields NotifyTimeout
forall a. Monoid a => [a] -> a
mconcat
[ String -> Mod OptionFields NotifyTimeout
forall (f :: Type -> Type) a. HasName f => String -> Mod f a
OA.long String
"notify-timeout",
String -> Mod OptionFields NotifyTimeout
forall (f :: Type -> Type) a. String -> Mod f a
Utils.mkHelpNoLine String
helpTxt,
String -> Mod OptionFields NotifyTimeout
forall (f :: Type -> Type) a. HasMetavar f => String -> Mod f a
OA.metavar ((Bool, [String]) -> String
forall a. (IsString a, Monoid a) => (Bool, [a]) -> a
ShrunUtils.mkMetaStr (Bool, [String])
forall a. IsString a => (Bool, [a])
Timeout.notifyTimeoutMeta)
]
helpTxt :: String
helpTxt =
[String] -> String
forall a. Monoid a => [a] -> a
mconcat
[ String
Item [String]
"When to timeout success notifications. Defaults to 10 seconds. ",
String
Item [String]
"Note that the underlying notification system may not support ",
String
Item [String]
"timeouts."
]