Fix addFlagReadParamAll for InputArgs case
parent
7132a79b50
commit
4b7f8681e7
|
@ -143,7 +143,7 @@ addFlagReadParamAll
|
||||||
-> Flag p
|
-> Flag p
|
||||||
-> (p -> f ())
|
-> (p -> f ())
|
||||||
-> CmdParser f out [p]
|
-> CmdParser f out [p]
|
||||||
addFlagReadParamAll shorts longs name flag act = addCmdPartManyA desc parseF act
|
addFlagReadParamAll shorts longs name flag act = addCmdPartManyInpA desc parseF act
|
||||||
where
|
where
|
||||||
allStrs = fmap (\c -> "-"++[c]) shorts
|
allStrs = fmap (\c -> "-"++[c]) shorts
|
||||||
++ fmap (\s -> "--"++s) longs
|
++ fmap (\s -> "--"++s) longs
|
||||||
|
@ -153,15 +153,23 @@ addFlagReadParamAll shorts longs name flag act = addCmdPartManyA desc parseF act
|
||||||
desc1 = PartAlts $ PartLiteral <$> allStrs
|
desc1 = PartAlts $ PartLiteral <$> allStrs
|
||||||
desc2 = (maybe id (PartDefault . show) $ _flag_default flag)
|
desc2 = (maybe id (PartDefault . show) $ _flag_default flag)
|
||||||
$ PartVariable name
|
$ PartVariable name
|
||||||
parseF :: String -> Maybe (p, String)
|
parseF :: Input -> Maybe (p, Input)
|
||||||
parseF str = flip firstJust allStrs
|
parseF inp = case inp of
|
||||||
$ \s -> [ t
|
InputString str -> flip firstJust allStrs $ \s ->
|
||||||
| (s ++ " ") `isPrefixOf` str
|
[ t
|
||||||
, t <- case Text.Read.reads $ drop (length s + 1) str of
|
| (s ++ " ") `isPrefixOf` str
|
||||||
((x, ' ':r):_) -> Just (x, dropWhile Char.isSpace r)
|
, let rest = drop (length s + 1) str
|
||||||
((x, []):_) -> Just (x, [])
|
, t <- case Text.Read.reads rest of
|
||||||
_ -> _flag_default flag <&> \x -> (x, s)
|
((x, ' ':r):_) -> Just (x, InputString $ dropWhile Char.isSpace r)
|
||||||
]
|
((x, ""):_) -> Just (x, InputString $ "")
|
||||||
|
_ -> _flag_default flag <&> \x -> (x, InputString rest)
|
||||||
|
]
|
||||||
|
InputArgs (arg1:argR) | any (==arg1) allStrs -> case argR of
|
||||||
|
[] -> _flag_default flag <&> \d -> (d, InputArgs argR)
|
||||||
|
(arg2:rest) -> case readMaybe arg2 of
|
||||||
|
Just x -> Just (x, InputArgs rest)
|
||||||
|
Nothing -> _flag_default flag <&> \d -> (d, InputArgs argR)
|
||||||
|
InputArgs _ -> Nothing
|
||||||
|
|
||||||
addFlagStringParam
|
addFlagStringParam
|
||||||
:: forall f out
|
:: forall f out
|
||||||
|
|
Loading…
Reference in New Issue