2015-07-10 06:18:08 +00:00
|
|
|
{- git-annex global options
|
|
|
|
-
|
addon commands
Seems only fair, that, like git runs git-annex, git-annex runs
git-annex-foo.
Implementation relies on O.forwardOptions, so that any options are passed
through to the addon program. Note that this includes options before the
subcommand, eg: git-annex -cx=y foo
Unfortunately, git-annex eats the --help/-h options.
This is because it uses O.hsubparser, which injects that option into each
subcommand. Seems like this should be possible to avoid somehow, to let
commands display their own --help, instead of the dummy one git-annex
displays.
The two step searching mirrors how git works, it makes finding
git-annex-foo fast when "git annex foo" is run, but will also support fuzzy
matching, once findAllAddonCommands gets implemented.
This commit was sponsored by Dr. Land Raider on Patreon.
2021-02-02 20:32:25 +00:00
|
|
|
- Copyright 2015-2021 Joey Hess <id@joeyh.name>
|
2015-07-10 06:18:08 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2015-07-10 06:18:08 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module CmdLine.GlobalSetter where
|
|
|
|
|
|
|
|
import Common
|
|
|
|
import Annex
|
2021-04-06 19:14:00 +00:00
|
|
|
import Types.DeferredParse
|
2015-07-10 06:18:08 +00:00
|
|
|
|
|
|
|
import Options.Applicative
|
|
|
|
|
2021-04-06 19:14:00 +00:00
|
|
|
setAnnexState :: Annex () -> GlobalSetter
|
|
|
|
setAnnexState a = GlobalSetter a id
|
|
|
|
|
|
|
|
setAnnexRead :: (AnnexRead -> AnnexRead) -> GlobalSetter
|
|
|
|
setAnnexRead f = GlobalSetter (return ()) f
|
2015-07-10 06:18:08 +00:00
|
|
|
|
2021-04-06 19:14:00 +00:00
|
|
|
globalFlag :: GlobalSetter -> Mod FlagFields GlobalSetter -> GlobalOption
|
|
|
|
globalFlag = flag'
|
2015-07-10 06:18:08 +00:00
|
|
|
|
2021-04-06 19:14:00 +00:00
|
|
|
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.
|
addon commands
Seems only fair, that, like git runs git-annex, git-annex runs
git-annex-foo.
Implementation relies on O.forwardOptions, so that any options are passed
through to the addon program. Note that this includes options before the
subcommand, eg: git-annex -cx=y foo
Unfortunately, git-annex eats the --help/-h options.
This is because it uses O.hsubparser, which injects that option into each
subcommand. Seems like this should be possible to avoid somehow, to let
commands display their own --help, instead of the dummy one git-annex
displays.
The two step searching mirrors how git works, it makes finding
git-annex-foo fast when "git annex foo" is run, but will also support fuzzy
matching, once findAllAddonCommands gets implemented.
This commit was sponsored by Dr. Land Raider on Patreon.
2021-02-02 20:32:25 +00:00
|
|
|
parserGlobalOptions :: [GlobalOption] -> Parser GlobalSetter
|
2021-04-06 19:14:00 +00:00
|
|
|
parserGlobalOptions [] = pure mempty
|
|
|
|
parserGlobalOptions l = mconcat <$> many (foldl1 (<|>) l)
|
|
|
|
|
|
|
|
applyAnnexReadSetter :: GlobalSetter -> (AnnexState, AnnexRead) -> (AnnexState, AnnexRead)
|
|
|
|
applyAnnexReadSetter gs (st, rd) = (st, annexReadSetter gs rd)
|