adjust: Allow any order of options when combining --hide-missing with options like --unlock.

optparse-applicative made this hard, the naive implementation this had
before didn't let --hide-missing come after --unlock. And just adding
additional <|> with --hide-missing coming after --unlock didn't work
either. So need to get some options and then combine them.
This commit is contained in:
Joey Hess 2024-10-21 16:03:29 -04:00
parent 2c14181bcb
commit bdf3a4747f
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 22 additions and 7 deletions

View file

@ -17,9 +17,24 @@ cmd = notBareRepo $ noDaemonRunning $
optParser :: CmdParamsDesc -> Parser Adjustment
optParser _ =
(LinkAdjustment <$> linkAdjustmentParser)
<|> (PresenceAdjustment <$> presenceAdjustmentParser <*> maybeLinkAdjustmentParser)
linkPresentAdjustmentParser
<|> (LockUnlockPresentAdjustment <$> lockUnlockPresentAdjustmentParser)
linkPresentAdjustmentParser :: Parser Adjustment
linkPresentAdjustmentParser = comb <$> some ps
where
ps = (LinkAdjustment <$> linkAdjustmentParser)
<|> (PresenceAdjustment <$> presenceAdjustmentParser <*> pure Nothing)
comb (LinkAdjustment _ : LinkAdjustment b : c) =
comb (LinkAdjustment b : c)
comb (PresenceAdjustment _a1 a2 : PresenceAdjustment b1 b2 : c) =
comb (PresenceAdjustment b1 (b2 <|> a2) : c)
comb (LinkAdjustment a : PresenceAdjustment b1 b2 : c) =
comb (PresenceAdjustment b1 (b2 <|> Just a) : c)
comb (PresenceAdjustment a1 _a2 : LinkAdjustment b : c) =
comb (PresenceAdjustment a1 (Just b) : c)
comb (a : _) = a
comb [] = error "internal"
linkAdjustmentParser :: Parser LinkAdjustment
linkAdjustmentParser =
@ -36,9 +51,6 @@ linkAdjustmentParser =
<> help "fix symlinks to annnexed files"
)
maybeLinkAdjustmentParser :: Parser (Maybe LinkAdjustment)
maybeLinkAdjustmentParser = Just <$> linkAdjustmentParser <|> pure Nothing
presenceAdjustmentParser :: Parser PresenceAdjustment
presenceAdjustmentParser =
flag' HideMissingAdjustment