required: New command, like wanted, but for required content.
Also refactored some code to reduce duplication.
This commit is contained in:
parent
c3732bddda
commit
ef2202fd94
8 changed files with 55 additions and 39 deletions
|
@ -13,6 +13,7 @@ import Command
|
|||
import Logs.PreferredContent
|
||||
import Types.Messages
|
||||
import Types.Group
|
||||
import Command.Wanted (performGet, performSet)
|
||||
|
||||
import qualified Data.Map as M
|
||||
|
||||
|
@ -24,22 +25,8 @@ seek :: CommandSeek
|
|||
seek = withWords start
|
||||
|
||||
start :: [String] -> CommandStart
|
||||
start (g:[]) = next $ performGet g
|
||||
start (g:[]) = next $ performGet groupPreferredContentMapRaw g
|
||||
start (g:expr:[]) = do
|
||||
showStart "groupwanted" g
|
||||
next $ performSet g expr
|
||||
next $ performSet groupPreferredContentSet expr g
|
||||
start _ = error "Specify a group."
|
||||
|
||||
performGet :: Group -> CommandPerform
|
||||
performGet g = do
|
||||
Annex.setOutput QuietOutput
|
||||
m <- groupPreferredContentMapRaw
|
||||
liftIO $ putStrLn $ fromMaybe "" $ M.lookup g m
|
||||
next $ return True
|
||||
|
||||
performSet :: Group -> String -> CommandPerform
|
||||
performSet g expr = case checkPreferredContentExpression expr of
|
||||
Just e -> error $ "Parse error: " ++ e
|
||||
Nothing -> do
|
||||
groupPreferredContentSet g expr
|
||||
next $ return True
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue