Skip to content

Commit

Permalink
Format usage line (fix #45).
Browse files Browse the repository at this point in the history
  • Loading branch information
pcapriotti committed Oct 14, 2013
1 parent b952989 commit 825a43e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Options/Applicative/Extra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,4 @@ usage :: ParserPrefs -> Parser a -> String -> Doc
usage pprefs p progn = hsep $
[ string "Usage:"
, string progn
, extract (briefDesc pprefs p) ]
, align (extract (briefDesc pprefs p)) ]
6 changes: 6 additions & 0 deletions Options/Applicative/Help/Chunk.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Options.Applicative.Help.Chunk
, chunked
, listToChunk
, (<<+>>)
, (<</>>)
, vcatChunks
, vsepChunks
, isEmpty
Expand Down Expand Up @@ -76,6 +77,11 @@ duplicate = fmap pure
(<<+>>) :: Chunk Doc -> Chunk Doc -> Chunk Doc
(<<+>>) = chunked (<+>)

-- | Concatenates two 'Chunk's with a softline in between. This is exactly like
-- '(<<+>>)', but uses a softline instead of a space.
(<</>>) :: Chunk Doc -> Chunk Doc -> Chunk Doc
(<</>>) = chunked (</>)

vcatChunks :: [Chunk Doc] -> Chunk Doc
vcatChunks = foldr (chunked (.$.)) mempty

Expand Down
4 changes: 2 additions & 2 deletions Options/Applicative/Help/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ briefDesc pprefs = fold_tree . treeMapParser (optDesc pprefs style)
, descSurround = True }

fold_tree (Leaf x) = x
fold_tree (MultNode xs) = foldr (<<+>>) mempty . map fold_tree $ xs
fold_tree (MultNode xs) = foldr (<</>>) mempty . map fold_tree $ xs
fold_tree (AltNode xs) = alt_node
. filter (not . isEmpty)
. map fold_tree $ xs

alt_node :: [Chunk Doc] -> Chunk Doc
alt_node [n] = n
alt_node ns = fmap parens
. foldr (chunked (mappendWith (string " | "))) mempty
. foldr (chunked (\x y -> x </> char '|' </> y)) mempty
$ ns

-- | Generate a full help text for a parser.
Expand Down

0 comments on commit 825a43e

Please sign in to comment.