adjust: Allow any order of options when combining --hide-missing with options like...
authorJoey Hess <joeyh@joeyh.name>
Mon, 21 Oct 2024 20:03:29 +0000 (16:03 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 21 Oct 2024 20:03:39 +0000 (16:03 -0400)
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.

CHANGELOG
Command/Adjust.hs
doc/bugs/git-annex-adjust_cares_about_argument_order.mdwn
doc/bugs/git-annex-adjust_cares_about_argument_order/comment_1_7d25bac61a284f0a6e890ca1736a9630._comment

index dc4598362ce15f2e16062cf503176a00d8dbdf9a..5bcfa04d253ecef5d68c1a3843cb471db2286b33 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -10,6 +10,8 @@ git-annex (10.20240928) UNRELEASED; urgency=medium
     allowing building with ghc 9.0.2.
   * git-remote-annex: Fix bug that prevented using it with external special
     remotes, leading to protocol error messages involving "GITMANIFEST".
+  * adjust: Allow any order of options when combining --hide-missing with
+    options like --unlock.
 
  -- Joey Hess <id@joeyh.name>  Thu, 17 Oct 2024 11:02:17 -0400
 
index 0bf04b6f70e7e90f46fe8cf7297cf99627a033b9..1d3bf8ea621b0290345003d6306b9c306b747da2 100644 (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
index ba563d816cc000798f77acf2221493ff4ac668ce..4e2b64d64eae2f530ac1e69c74811b53663b76eb 100644 (file)
@@ -40,3 +40,5 @@ This is admittedly arguably consistent with https://git-annex.branchable.com/git
 ### Have you had any luck using git-annex before? (Sometimes we get tired of reading bug reports all day and a lil' positive end note does wonders)
 
 Yes, I've been really happy using it to manage a bunch of videos, where I only need some on my laptop at any given time. Way better than my previous "manually scp things around" strategy.
+
+> [[fixed|done]] --[[Joey]] 
index 1aeec49b58bac2b5a53f6b3ac305ac82b4df88b2..c7fa3febf3cd70cb8e4e873f5cc43648d88184a6 100644 (file)
@@ -3,6 +3,5 @@
  subject="""comment 1"""
  date="2024-10-21T19:06:47Z"
  content="""
-This is not intentional behavior, and is surprising. I don't think an
-applicative option parser should ever behave this way. Weird!
+Surprising and unintentional! Fixed this.
 """]]