module Vimeta.UI.CommandLine.Common
( CommonOptions,
commonOptions,
updateConfig,
)
where
import Options.Applicative
import Vimeta.Core
data CommonOptions = CommonOptions
{ CommonOptions -> Bool
optsVerbose :: Bool,
CommonOptions -> Bool
optsDryRun :: Bool
}
commonOptions :: Parser CommonOptions
commonOptions :: Parser CommonOptions
commonOptions =
Bool -> Bool -> CommonOptions
CommonOptions (Bool -> Bool -> CommonOptions)
-> Parser Bool -> Parser (Bool -> CommonOptions)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mod FlagFields Bool -> Parser Bool
switch Mod FlagFields Bool
forall a. Mod FlagFields a
infoVerbose
Parser (Bool -> CommonOptions)
-> Parser Bool -> Parser CommonOptions
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mod FlagFields Bool -> Parser Bool
switch Mod FlagFields Bool
forall a. Mod FlagFields a
infoDryRun
where
infoVerbose :: Mod FlagFields a
infoVerbose = String -> Mod FlagFields a
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"verbose" Mod FlagFields a -> Mod FlagFields a -> Mod FlagFields a
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields a
forall (f :: * -> *) a. String -> Mod f a
help String
"Enable verbose output"
infoDryRun :: Mod FlagFields a
infoDryRun =
Char -> Mod FlagFields a
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'd' Mod FlagFields a -> Mod FlagFields a -> Mod FlagFields a
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields a
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"dry-run"
Mod FlagFields a -> Mod FlagFields a -> Mod FlagFields a
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields a
forall (f :: * -> *) a. String -> Mod f a
help String
"Don't tag files, implies --verbose"
updateConfig :: CommonOptions -> Config -> Config
updateConfig :: CommonOptions -> Config -> Config
updateConfig CommonOptions
o Config
c =
Config
c
{ configVerbose :: Bool
configVerbose = Config -> Bool
configVerbose Config
c Bool -> Bool -> Bool
|| CommonOptions -> Bool
optsVerbose CommonOptions
o,
configDryRun :: Bool
configDryRun = Config -> Bool
configDryRun Config
c Bool -> Bool -> Bool
|| CommonOptions -> Bool
optsDryRun CommonOptions
o
}