Skip to content

Commit 3caa03a

Browse files
committed
Unified Enable/disable help messaging
Per issue #1613, enable/disable flags now occupy 1 line in help output. Summary: - Simplified `enableDisableNoDefault` logic as hiding is no longer specified manually. - Helper function `enableDisableNoDefault'` no longer seemed necessary after simplification, removed it. - Fixed issues caused by removing the show/hide argument - Created "dummy" extra flag with appropriate help message Issue: dummy argmuent actually acts as a real flag, which seems bad. `<*` was causing the hidden actual flags to be dropped by opt-parse. Ideally this would cause the standard unknown command behavior.
1 parent c1212c9 commit 3caa03a

File tree

1 file changed

+15
-33
lines changed

1 file changed

+15
-33
lines changed

src/Options/Applicative/Builder/Extra.hs

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ boolFlags :: Bool -- ^ Default value
2929
boolFlags defaultValue = enableDisableFlags defaultValue True False
3030

3131
-- | Enable/disable flags for a 'Bool', without a default case (to allow chaining with '<|>').
32-
boolFlagsNoDefault :: Maybe Bool -- ^ Hide the enabling or disabling flag from the
33-
-- brief description?
34-
-> String -- ^ Flag name
32+
boolFlagsNoDefault :: String -- ^ Flag name
3533
-> String -- ^ Help suffix
3634
-> Mod FlagFields Bool
3735
-> Parser Bool
@@ -54,54 +52,38 @@ enableDisableFlags :: (Eq a)
5452
-> Mod FlagFields a
5553
-> Parser a
5654
enableDisableFlags defaultValue enabledValue disabledValue name helpSuffix mods =
57-
enableDisableFlagsNoDefault enabledValue disabledValue (Just defaultValue) name helpSuffix mods <|>
55+
enableDisableFlagsNoDefault enabledValue disabledValue name helpSuffix mods <|>
5856
pure defaultValue
5957

6058
-- | Enable/disable flags for any type, without a default (to allow chaining with '<|>')
6159
enableDisableFlagsNoDefault :: (Eq a)
6260
=> a -- ^ Enabled value
6361
-> a -- ^ Disabled value
64-
-> Maybe a -- ^ Hide the enabling or disabling flag
65-
-- from the brief description??
6662
-> String -- ^ Name
6763
-> String -- ^ Help suffix
6864
-> Mod FlagFields a
6965
-> Parser a
70-
enableDisableFlagsNoDefault enabledValue disabledValue maybeHideValue name helpSuffix mods =
71-
last <$> some (enableDisableFlagsNoDefault' enabledValue disabledValue maybeHideValue name helpSuffix mods)
72-
73-
enableDisableFlagsNoDefault' :: (Eq a) => a -> a -> Maybe a -> String -> String -> Mod FlagFields a -> Parser a
74-
enableDisableFlagsNoDefault' enabledValue disabledValue maybeHideValue name helpSuffix mods =
75-
let hideEnabled = Just enabledValue == maybeHideValue
76-
hideDisabled = Just disabledValue == maybeHideValue
77-
in flag'
66+
enableDisableFlagsNoDefault enabledValue disabledValue name helpSuffix mods =
67+
last <$> some
68+
((flag'
7869
enabledValue
79-
((if hideEnabled
80-
then hidden <> internal
81-
else idm) <>
70+
(hidden <>
71+
internal <>
8272
long name <>
83-
help
84-
(concat $ concat
85-
[ ["Enable ", helpSuffix]
86-
, [" (--no-" ++ name ++ " to disable)" | hideDisabled]]) <>
73+
help helpSuffix <>
8774
mods) <|>
88-
flag'
89-
enabledValue
90-
(hidden <> internal <> long ("enable-" ++ name) <> mods) <|>
9175
flag'
9276
disabledValue
93-
((if hideDisabled
94-
then hidden <> internal
95-
else idm) <>
77+
(hidden <>
78+
internal <>
9679
long ("no-" ++ name) <>
97-
help
98-
(concat $ concat
99-
[ ["Disable ", helpSuffix]
100-
, [" (--" ++ name ++ " to enable)" | hideEnabled]]) <>
101-
mods) <|>
80+
help helpSuffix <>
81+
mods)) <|>
10282
flag'
10383
disabledValue
104-
(hidden <> internal <> long ("disable-" ++ name) <> mods)
84+
(long (concat ["[no-]", name]) <>
85+
help (concat ["Enable/disable ", helpSuffix]) <>
86+
mods))
10587

10688
-- | Show an extra help option (e.g. @--docker-help@ shows help for all @--docker*@ args).
10789
--

0 commit comments

Comments
 (0)