d16d739ce2
Most of the changes here involve global option parsing: GlobalSetter changed so it can both run an Annex action to set state, but can also change the AnnexRead value, which is immutable once the Annex monad is running. That allowed a debugselector value to be added to AnnexRead, seeded from the git config. The --debugfilter option's GlobalSetter then updates the AnnexRead. This improved GlobalSetter can later be used to move more stuff to AnnexRead. Things that don't involve a git config will be easier to move, and probably a *lot* of things can be moved eventually. fastDebug, while implemented, is not used anywhere yet. But it should be fast..
36 lines
1.1 KiB
Haskell
36 lines
1.1 KiB
Haskell
{- git-annex global options
|
|
-
|
|
- Copyright 2015-2021 Joey Hess <id@joeyh.name>
|
|
-
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
|
-}
|
|
|
|
module CmdLine.GlobalSetter where
|
|
|
|
import Common
|
|
import Annex
|
|
import Types.DeferredParse
|
|
|
|
import Options.Applicative
|
|
|
|
setAnnexState :: Annex () -> GlobalSetter
|
|
setAnnexState a = GlobalSetter a id
|
|
|
|
setAnnexRead :: (AnnexRead -> AnnexRead) -> GlobalSetter
|
|
setAnnexRead f = GlobalSetter (return ()) f
|
|
|
|
globalFlag :: GlobalSetter -> Mod FlagFields GlobalSetter -> GlobalOption
|
|
globalFlag = flag'
|
|
|
|
globalOption :: (v -> GlobalSetter) -> Parser v -> GlobalOption
|
|
globalOption mk parser = mk <$> parser
|
|
|
|
-- | Combines a bunch of GlobalOptions together into a Parser
|
|
-- that returns a GlobalSetter that can be used to set all the options that
|
|
-- are enabled.
|
|
parserGlobalOptions :: [GlobalOption] -> Parser GlobalSetter
|
|
parserGlobalOptions [] = pure mempty
|
|
parserGlobalOptions l = mconcat <$> many (foldl1 (<|>) l)
|
|
|
|
applyAnnexReadSetter :: GlobalSetter -> (AnnexState, AnnexRead) -> (AnnexState, AnnexRead)
|
|
applyAnnexReadSetter gs (st, rd) = (st, annexReadSetter gs rd)
|