Commit 6b0c3009 authored by Mikhail Glushenkov's avatar Mikhail Glushenkov
Browse files

Make 'trueArg'/'falseArg' create a 'BoolOpt' instead of 'ChoiceOpt'.

'ChoiceOpt' is really an enum, when we were using it is a boolean the default
value wasn't printed correctly in the config file.

Before:

-- hscolour:

After:

-- hscolour: False
parent 90dc9f9d
...@@ -222,7 +222,11 @@ viewAsGetOpt (OptionField _n aa) = concatMap optDescrToGetOpt aa ...@@ -222,7 +222,11 @@ viewAsGetOpt (OptionField _n aa) = concatMap optDescrToGetOpt aa
set' (Just txt) = readEOrFail set txt set' (Just txt) = readEOrFail set txt
optDescrToGetOpt (ChoiceOpt alts) = optDescrToGetOpt (ChoiceOpt alts) =
[GetOpt.Option sf lf (GetOpt.NoArg set) d | (d,(sf,lf),set,_) <- alts ] [GetOpt.Option sf lf (GetOpt.NoArg set) d | (d,(sf,lf),set,_) <- alts ]
optDescrToGetOpt (BoolOpt d (sfT,lfT) (sfF, lfF) set _) = optDescrToGetOpt (BoolOpt d (sfT, lfT) ([], []) set _) =
[ GetOpt.Option sfT lfT (GetOpt.NoArg (set True)) d ]
optDescrToGetOpt (BoolOpt d ([], []) (sfF, lfF) set _) =
[ GetOpt.Option sfF lfF (GetOpt.NoArg (set False)) d ]
optDescrToGetOpt (BoolOpt d (sfT,lfT) (sfF, lfF) set _) =
[ GetOpt.Option sfT lfT (GetOpt.NoArg (set True)) ("Enable " ++ d) [ GetOpt.Option sfT lfT (GetOpt.NoArg (set True)) ("Enable " ++ d)
, GetOpt.Option sfF lfF (GetOpt.NoArg (set False)) ("Disable " ++ d) ] , GetOpt.Option sfF lfF (GetOpt.NoArg (set False)) ("Disable " ++ d) ]
...@@ -329,12 +333,15 @@ commandShowOptions command v = concat ...@@ -329,12 +333,15 @@ commandShowOptions command v = concat
[ showOptDescr v od | o <- commandOptions command ParseArgs [ showOptDescr v od | o <- commandOptions command ParseArgs
, od <- optionDescr o] , od <- optionDescr o]
where where
maybePrefix [] = []
maybePrefix (lOpt:_) = ["--" ++ lOpt]
showOptDescr :: a -> OptDescr a -> [String] showOptDescr :: a -> OptDescr a -> [String]
showOptDescr x (BoolOpt _ (_,lfT:_) (_,lfF:_) _ enabled) showOptDescr x (BoolOpt _ (_,lfTs) (_,lfFs) _ enabled)
= case enabled x of = case enabled x of
Nothing -> [] Nothing -> []
Just True -> ["--" ++ lfT] Just True -> maybePrefix lfTs
Just False -> ["--" ++ lfF] Just False -> maybePrefix lfFs
showOptDescr x c@ChoiceOpt{} showOptDescr x c@ChoiceOpt{}
= ["--" ++ val | val <- getCurrentChoice c x] = ["--" ++ val | val <- getCurrentChoice c x]
showOptDescr x (ReqArg _ (_ssff,lf:_) _ _ showflag) showOptDescr x (ReqArg _ (_ssff,lf:_) _ _ showflag)
......
...@@ -1840,10 +1840,9 @@ boolOpt' :: OptFlags -> OptFlags ...@@ -1840,10 +1840,9 @@ boolOpt' :: OptFlags -> OptFlags
-> MkOptDescr (a -> Flag Bool) (Flag Bool -> a -> a) a -> MkOptDescr (a -> Flag Bool) (Flag Bool -> a -> a) a
boolOpt' = Command.boolOpt' flagToMaybe Flag boolOpt' = Command.boolOpt' flagToMaybe Flag
trueArg, falseArg :: SFlags -> LFlags -> Description -> (b -> Flag Bool) -> trueArg, falseArg :: MkOptDescr (a -> Flag Bool) (Flag Bool -> a -> a) a
(Flag Bool -> (b -> b)) -> OptDescr b trueArg sfT lfT = boolOpt' (sfT, lfT) ([], []) sfT lfT
trueArg = noArg (Flag True) falseArg sfF lfF = boolOpt' ([], []) (sfF, lfF) sfF lfF
falseArg = noArg (Flag False)
reqArgFlag :: ArgPlaceHolder -> SFlags -> LFlags -> Description -> reqArgFlag :: ArgPlaceHolder -> SFlags -> LFlags -> Description ->
(b -> Flag String) -> (Flag String -> b -> b) -> OptDescr b (b -> Flag String) -> (Flag String -> b -> b) -> OptDescr b
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment