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
( NotifyArgs,
NotifyP (MkNotifyP, action, system, timeout),
)
import Shrun.Configuration.Data.WithDisabled (WithDisabled)
import Shrun.Notify.Types (NotifyAction, NotifySystemArgs, NotifyTimeout)
import Shrun.Notify.Types qualified as Notify
import Shrun.Prelude
notifyParser :: Parser NotifyArgs
notifyParser :: Parser NotifyArgs
notifyParser = do
WithDisabled NotifyAction
action <- Parser (WithDisabled NotifyAction)
notifyActionParser
WithDisabled (NotifySystemP 'ConfigPhaseArgs)
system <- Parser (WithDisabled (NotifySystemP 'ConfigPhaseArgs))
notifySystemParser
WithDisabled NotifyTimeout
timeout <- Parser (WithDisabled NotifyTimeout)
notifyTimeoutParser
pure
$ MkNotifyP
{ WithDisabled NotifyAction
NotifyActionF 'ConfigPhaseArgs
action :: NotifyActionF 'ConfigPhaseArgs
action :: WithDisabled NotifyAction
action,
WithDisabled (NotifySystemP 'ConfigPhaseArgs)
ConfigPhaseF 'ConfigPhaseArgs (NotifySystemP 'ConfigPhaseArgs)
system :: ConfigPhaseF 'ConfigPhaseArgs (NotifySystemP 'ConfigPhaseArgs)
system :: WithDisabled (NotifySystemP 'ConfigPhaseArgs)
system,
WithDisabled NotifyTimeout
ConfigPhaseF 'ConfigPhaseArgs NotifyTimeout
timeout :: ConfigPhaseF 'ConfigPhaseArgs NotifyTimeout
timeout :: WithDisabled NotifyTimeout
timeout
}
notifyActionParser :: Parser (WithDisabled NotifyAction)
notifyActionParser :: Parser (WithDisabled NotifyAction)
notifyActionParser = Parser (Maybe NotifyAction)
-> String -> Parser (WithDisabled NotifyAction)
forall a. Parser (Maybe a) -> String -> Parser (WithDisabled a)
Utils.withDisabledParser Parser (Maybe NotifyAction)
mainParser String
"notify-action"
where
mainParser :: Parser (Maybe NotifyAction)
mainParser =
Parser NotifyAction -> Parser (Maybe NotifyAction)
forall (f :: Type -> Type) a. Alternative f => f a -> f (Maybe a)
OA.optional
(Parser NotifyAction -> Parser (Maybe NotifyAction))
-> Parser NotifyAction -> Parser (Maybe NotifyAction)
forall a b. (a -> b) -> a -> b
$ ReadM NotifyAction
-> Mod OptionFields NotifyAction -> Parser NotifyAction
forall a. ReadM a -> Mod OptionFields a -> Parser a
OA.option (ReadM Text -> ReadM NotifyAction
forall (m :: Type -> Type). MonadFail m => m Text -> m NotifyAction
Notify.parseNotifyAction ReadM Text
forall s. IsString s => ReadM s
OA.str)
(Mod OptionFields NotifyAction -> Parser NotifyAction)
-> Mod OptionFields NotifyAction -> Parser NotifyAction
forall a b. (a -> b) -> a -> b
$ [Mod OptionFields NotifyAction] -> Mod OptionFields NotifyAction
forall a. Monoid a => [a] -> a
mconcat
[ String -> Mod OptionFields NotifyAction
forall (f :: Type -> Type) a. HasName f => String -> Mod f a
OA.long String
"notify-action",
String -> Mod OptionFields NotifyAction
forall (f :: Type -> Type) a. String -> Mod f a
Utils.mkHelp String
helpTxt,
String -> Mod OptionFields NotifyAction
forall (f :: Type -> Type) a. HasMetavar f => String -> Mod f a
OA.metavar String
forall a. IsString a => a
Notify.notifyActionStr
]
helpTxt :: String
helpTxt =
[String] -> String
forall a. Monoid a => [a] -> a
mconcat
[ String
"Sends notifications for various actions. 'Final' sends off a ",
String
"notification when Shrun itself finishes whereas 'command' sends ",
String
"off one each time a command finishes. 'All' implies 'final' and ",
String
"'command'."
]
notifySystemParser :: Parser (WithDisabled NotifySystemArgs)
notifySystemParser :: Parser (WithDisabled (NotifySystemP 'ConfigPhaseArgs))
notifySystemParser = Parser (Maybe (NotifySystemP 'ConfigPhaseArgs))
-> String -> Parser (WithDisabled (NotifySystemP 'ConfigPhaseArgs))
forall a. Parser (Maybe a) -> String -> Parser (WithDisabled a)
Utils.withDisabledParser Parser (Maybe (NotifySystemP 'ConfigPhaseArgs))
mainParser String
"notify-system"
where
mainParser :: Parser (Maybe (NotifySystemP 'ConfigPhaseArgs))
mainParser =
Parser (NotifySystemP 'ConfigPhaseArgs)
-> Parser (Maybe (NotifySystemP 'ConfigPhaseArgs))
forall (f :: Type -> Type) a. Alternative f => f a -> f (Maybe a)
OA.optional
(Parser (NotifySystemP 'ConfigPhaseArgs)
-> Parser (Maybe (NotifySystemP 'ConfigPhaseArgs)))
-> Parser (NotifySystemP 'ConfigPhaseArgs)
-> Parser (Maybe (NotifySystemP 'ConfigPhaseArgs))
forall a b. (a -> b) -> a -> b
$ ReadM (NotifySystemP 'ConfigPhaseArgs)
-> Mod OptionFields (NotifySystemP 'ConfigPhaseArgs)
-> Parser (NotifySystemP 'ConfigPhaseArgs)
forall a. ReadM a -> Mod OptionFields a -> Parser a
OA.option (ReadM Text -> ReadM (NotifySystemP 'ConfigPhaseArgs)
forall (p :: ConfigPhase) (m :: Type -> Type).
(DBusF p ~ (), MonadFail m) =>
m Text -> m (NotifySystemP p)
Notify.parseNotifySystem ReadM Text
forall s. IsString s => ReadM s
OA.str)
(Mod OptionFields (NotifySystemP 'ConfigPhaseArgs)
-> Parser (NotifySystemP 'ConfigPhaseArgs))
-> Mod OptionFields (NotifySystemP 'ConfigPhaseArgs)
-> Parser (NotifySystemP 'ConfigPhaseArgs)
forall a b. (a -> b) -> a -> b
$ [Mod OptionFields (NotifySystemP 'ConfigPhaseArgs)]
-> Mod OptionFields (NotifySystemP 'ConfigPhaseArgs)
forall a. Monoid a => [a] -> a
mconcat
[ String -> Mod OptionFields (NotifySystemP 'ConfigPhaseArgs)
forall (f :: Type -> Type) a. HasName f => String -> Mod f a
OA.long String
"notify-system",
String -> Mod OptionFields (NotifySystemP 'ConfigPhaseArgs)
forall (f :: Type -> Type) a. String -> Mod f a
Utils.mkHelp String
helpTxt,
String -> Mod OptionFields (NotifySystemP 'ConfigPhaseArgs)
forall (f :: Type -> Type) a. HasMetavar f => String -> Mod f a
OA.metavar String
forall a. IsString a => a
Notify.notifySystemStr
]
helpTxt :: String
helpTxt =
[String] -> String
forall a. Monoid a => [a] -> a
mconcat
[ String
"The system used for sending notifications. 'dbus' and 'notify-send' ",
String
"available on linux, whereas 'apple-script' is available for osx."
]
notifyTimeoutParser :: Parser (WithDisabled NotifyTimeout)
notifyTimeoutParser :: Parser (WithDisabled NotifyTimeout)
notifyTimeoutParser = Parser (Maybe NotifyTimeout)
-> String -> Parser (WithDisabled NotifyTimeout)
forall a. Parser (Maybe a) -> String -> Parser (WithDisabled a)
Utils.withDisabledParser Parser (Maybe NotifyTimeout)
mainParser String
"notify-timeout"
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
Notify.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.mkHelp String
helpTxt,
String -> Mod OptionFields NotifyTimeout
forall (f :: Type -> Type) a. HasMetavar f => String -> Mod f a
OA.metavar String
forall a. IsString a => a
Notify.notifyTimeoutStr
]
helpTxt :: String
helpTxt =
[String] -> String
forall a. Monoid a => [a] -> a
mconcat
[ String
"When to timeout success notifications. Defaults to 10 seconds.",
String
"Note that the underlying notification system may not support ",
String
"timeouts."
]