aboutsummaryrefslogtreecommitdiff
path: root/Command
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2017-01-30 16:41:29 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2017-01-30 16:46:38 -0400
commit9b17947b394cc2720b15aaf44e6fb7703ba8513f (patch)
treed97e570df7bf859031713d3963baf4be7f65bfbf /Command
parentdc2095666d7b8e39ec3e1f2f26dca7eceff34877 (diff)
config: New command for storing configuration in the git-annex branch.
Any config names can be set using this; git-annex commands will only look at specific ones that make sense and are worth the overhead of querying the branch. This might also be useful for storing whatever other config-type stuff the user might want to shove into the git-annex branch. This commit was sponsored by Jochen Bartl on Patreon.
Diffstat (limited to 'Command')
-rw-r--r--Command/Config.hs65
1 files changed, 65 insertions, 0 deletions
diff --git a/Command/Config.hs b/Command/Config.hs
new file mode 100644
index 000000000..690c8d288
--- /dev/null
+++ b/Command/Config.hs
@@ -0,0 +1,65 @@
+{- git-annex command
+ -
+ - Copyright 2017 Joey Hess <id@joeyh.name>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Command.Config where
+
+import Command
+import Logs.Config
+
+cmd :: Command
+cmd = command "config" SectionSetup "configuration stored in git-annex branch"
+ paramNothing (seek <$$> optParser)
+
+data Action
+ = SetConfig ConfigName ConfigValue
+ | GetConfig ConfigName
+ | UnsetConfig ConfigName
+
+type Name = String
+type Value = String
+
+optParser :: CmdParamsDesc -> Parser Action
+optParser _ = setconfig <|> getconfig <|> unsetconfig
+ where
+ setconfig = SetConfig
+ <$> strOption
+ ( long "set"
+ <> help "set configuration"
+ <> metavar paramName
+ )
+ <*> strArgument
+ ( metavar paramValue
+ )
+ getconfig = GetConfig <$> strOption
+ ( long "get"
+ <> help "get configuration"
+ <> metavar paramName
+ )
+ unsetconfig = UnsetConfig <$> strOption
+ ( long "unset"
+ <> help "unset configuration"
+ <> metavar paramName
+ )
+
+seek :: Action -> CommandSeek
+seek (SetConfig name val) = commandAction $ do
+ showStart name val
+ next $ next $ do
+ setGlobalConfig name val
+ return True
+seek (UnsetConfig name) = commandAction $ do
+ showStart name "unset"
+ next $ next $ do
+ unsetGlobalConfig name
+ return True
+seek (GetConfig name) = commandAction $ do
+ mv <- getGlobalConfig name
+ case mv of
+ Nothing -> stop
+ Just v -> do
+ liftIO $ putStrLn v
+ stop