@@ -36,16 +36,26 @@ replOnlyOptions = Set.fromList [
36
36
37
37
rejectUnsupportedOptions :: [String ] -> IO ()
38
38
rejectUnsupportedOptions args = case getOpt' Permute options args of
39
- (_, _, unsupported : _, _) -> die $ " Error: cabal: unrecognized 'doctest' option `" <> unsupported <> " '"
39
+ (xs, _, _, _) | ListOptions `elem` xs -> do
40
+ let
41
+ names :: [String ]
42
+ names = concat [map (\ c -> [' -' , c]) short ++ map (" --" <> ) long | Option short long _ _ <- documentedOptions]
43
+ putStr (unlines names)
44
+ exitSuccess
45
+ (_, _, unsupported : _, _) -> do
46
+ die $ " Error: cabal: unrecognized 'doctest' option `" <> unsupported <> " '"
40
47
_ -> pass
41
48
42
- data Argument = Argument {
43
- argumentName :: String
44
- , argumentValue :: Maybe String
45
- }
49
+ data Argument = Argument String (Maybe String ) | ListOptions
50
+ deriving (Eq , Show )
46
51
47
52
options :: [OptDescr Argument ]
48
- options = map toOptDescr Repl. options
53
+ options =
54
+ Option [] [" list-options" ] (NoArg ListOptions ) " "
55
+ : documentedOptions
56
+
57
+ documentedOptions :: [OptDescr Argument ]
58
+ documentedOptions = map toOptDescr Repl. options
49
59
where
50
60
toOptDescr :: Repl. Option -> OptDescr Argument
51
61
toOptDescr (Repl. Option long short arg help) = Option (maybeToList short) [long] (toArgDescr long arg) help
@@ -57,17 +67,8 @@ options = map toOptDescr Repl.options
57
67
Repl. OptionalArgument name -> OptArg argument name
58
68
where
59
69
argument :: Maybe String -> Argument
60
- argument argumentValue = Argument {
61
- argumentName = " --" <> long
62
- , argumentValue
63
- }
70
+ argument value = Argument (" --" <> long) value
64
71
65
72
discardReplOptions :: [String ] -> [String ]
66
73
discardReplOptions args = case getOpt Permute options args of
67
- (xs, _, _) -> concatMap values (filter (not . isReplOnlyOption) xs)
68
- where
69
- isReplOnlyOption :: Argument -> Bool
70
- isReplOnlyOption arg = Set. member (argumentName arg) replOnlyOptions
71
-
72
- values :: Argument -> [String ]
73
- values (Argument name value) = name : maybeToList value
74
+ (xs, _, _) -> concat [name : maybeToList value | Argument name value <- xs, Set. notMember name replOnlyOptions]
0 commit comments