You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like the ability to have option parsing stop on the first non-flag argument encountered, to prevent having to always use "--" for a command that is a runner for other programs with their own arguments.
I had a go at adding a strict version of arguments and arguments1, but had trouble with the tests and wasn't sure how to best integrate it. Here's what I came up with which only supports non-interspersed mode, if that's useful:
arguments_ allow_empty p m = set_default <$> fromM args1
where
Mod f (DefaultProp def sdef) g = m
show_def = sdef <*> def
props = mkProps mempty g
props' = (mkProps mempty g) { propShowDefault = show_def }
args1 | allow_empty = args
| otherwise = do
mx <- oneM arg_or_ddash
case mx of
Nothing -> someM arg
Just x -> (x:) <$> manyM arg
args = do
mx <- oneM $ optional arg_or_ddash
case mx of
Nothing -> return []
Just Nothing -> manyM arg
Just (Just x) -> (x:) <$> manyM arg
arg_or_ddash = (ddash *> pure Nothing) <|> (p <$> nonOpt)
set_default [] = fromMaybe [] def
set_default xs = xs
arg = liftOpt (Option (ArgReader (CReader compl p)) props)
ddash :: Parser ()
ddash = argument' (guard . (== "--")) internal
nonOpt = argument' nonOpt' internal
nonOpt' ('-':_) = Nothing
nonOpt' a = Just a
ArgumentFields compl = f (ArgumentFields mempty)
caveat: this could be wrong, I don't fully understand the code yet ;). Seems to work in the cases I threw at it though.
It could be a better idea to have this flag be over the whole of argument parsing, rather than built into the arguments parser. But I'm not even sure if that's possible with the current structure of parsers.
The text was updated successfully, but these errors were encountered:
It could be a better idea to have this flag be over the whole of argument parsing, rather than built into the arguments parser. But I'm not even sure if that's possible with the current structure of parsers.
I agree, this should be handled at the lower level.
I'd like the ability to have option parsing stop on the first non-flag argument encountered, to prevent having to always use "--" for a command that is a runner for other programs with their own arguments.
(like python's optparse, when `disable_interspersed_args() is called):
http://docs.python.org/library/optparse.html#optparse.OptionParser.disable_interspersed_args
I had a go at adding a
strict
version of arguments and arguments1, but had trouble with the tests and wasn't sure how to best integrate it. Here's what I came up with which only supports non-interspersed mode, if that's useful:caveat: this could be wrong, I don't fully understand the code yet ;). Seems to work in the cases I threw at it though.
It could be a better idea to have this flag be over the whole of argument parsing, rather than built into the
arguments
parser. But I'm not even sure if that's possible with the current structure of parsers.The text was updated successfully, but these errors were encountered: