Skip to content

Commit c705a71

Browse files
committed
Add documentation for backtracking options
1 parent 4f91f86 commit c705a71

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/Options/Applicative/Builder.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,14 +555,17 @@ showHelpOnEmpty :: PrefsMod
555555
showHelpOnEmpty = PrefsMod $ \p -> p { prefShowHelpOnEmpty = True }
556556

557557
-- | Turn off backtracking after subcommand is parsed.
558+
--
559+
-- /NOTE:/ When this option is used, all remaining arguments /must/ be
560+
-- consumed by the subcommand once it entered.
558561
noBacktrack :: PrefsMod
559562
noBacktrack = PrefsMod $ \p -> p { prefBacktrack = NoBacktrack }
560563

561-
-- | Allow full mixing of subcommand and parent arguments by inlining
564+
-- | Allow full mixing of subcommand and parent arguments by embedding
562565
-- selected subparsers into the parent parser.
563566
--
564567
-- /NOTE:/ When this option is used, preferences for the subparser which
565-
-- effect the parser behaviour (such as noIntersperse) are ignored.
568+
-- effect the parser behaviour (such as @noIntersperse@) are ignored.
566569
subparserInline :: PrefsMod
567570
subparserInline = PrefsMod $ \p -> p { prefBacktrack = SubparserInline }
568571

src/Options/Applicative/Types.hs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,27 @@ data ParserInfo a = ParserInfo
102102
instance Functor ParserInfo where
103103
fmap f i = i { infoParser = fmap f (infoParser i) }
104104

105+
-- | Behaviour for how subcommands are executed within a parser.
105106
data Backtracking
107+
-- | When a subcommand is complete, parsing will drop back to the parent
108+
-- command (this is the default behaviour).
109+
--
110+
-- /NOTE:/ Options which aren't recognised by the subcommand may be tried
111+
-- by the parent (if the subcommand is satisfied) and errors raised against
112+
-- the parent parser.
106113
= Backtrack
114+
-- | Subcommands do not drop back to the parent when complete, and must
115+
-- consume all remaining arguments provided.
116+
--
117+
-- This means that multiple sub-commands can not be required at the same
118+
-- level, and all global options /must/ be specified before entering the
119+
-- subcommand.
107120
| NoBacktrack
121+
-- | Subcommands are embeddeed into the parent parser, allowing full mixing
122+
-- of their arguments and that of their parent.
123+
--
124+
-- /NOTE:/ When this option is used, preferences for the subparser which
125+
-- effect the parser behaviour (such as 'noIntersperse') are ignored.
108126
| SubparserInline
109127
deriving (Eq, Show)
110128

0 commit comments

Comments
 (0)