Forbid "leftover" args to interactive commands

This commit is contained in:
Nikolay Yakimov 2015-12-20 06:41:34 +03:00
parent a1079f22a0
commit d0c53ec937
3 changed files with 5 additions and 8 deletions

View File

@ -110,7 +110,7 @@ legacyInteractiveLoop symdbreq world = do
res <- flip gcatches interactiveHandlers $ do res <- flip gcatches interactiveHandlers $ do
pargs <- maybe (throw $ InvalidCommandLine $ Left cmdArg) return pargs <- maybe (throw $ InvalidCommandLine $ Left cmdArg) return
$ parseArgsInteractive cmdArg $ parseArgsInteractive cmdArg
case fst pargs of case pargs of
CmdFind symbol -> CmdFind symbol ->
lookupSymbol symbol =<< checkDb symdbreq =<< getDb symdbreq lookupSymbol symbol =<< checkDb symdbreq =<< getDb symdbreq

View File

@ -37,7 +37,7 @@ parseArgs =
$$ fullDesc $$ fullDesc
<=> header "ghc-mod: Happy Haskell Programming" <=> header "ghc-mod: Happy Haskell Programming"
parseArgsInteractive :: String -> Maybe (GhcModCommands, [String]) parseArgsInteractive :: String -> Maybe GhcModCommands
parseArgsInteractive args = parseArgsInteractive args =
getParseResult $ execParserPure (prefs idm) opts $ parseCmdLine args getParseResult $ execParserPure (prefs idm) opts $ parseCmdLine args
where where

View File

@ -179,12 +179,10 @@ commands =
, text "(See also: https://github.com/kazu-yamamoto/ghc-mod/issues/311)" , text "(See also: https://github.com/kazu-yamamoto/ghc-mod/issues/311)"
] ]
interactiveCommandsSpec :: Parser (GhcModCommands, [String]) interactiveCommandsSpec :: Parser GhcModCommands
interactiveCommandsSpec = interactiveCommandsSpec =
(,) <$> subparser' icmds <*> leftover subparser'
where $ commands
icmds =
commands
<> command "map-file" <> command "map-file"
$$ info (helper <*> mapArgSpec) $$ info (helper <*> mapArgSpec)
$$ progDesc "tells ghc-modi to read `file.hs` source from stdin" $$ progDesc "tells ghc-modi to read `file.hs` source from stdin"
@ -201,7 +199,6 @@ interactiveCommandsSpec =
$$ progDesc "Exit interactive mode" $$ progDesc "Exit interactive mode"
<> command "" <> command ""
$$ info (pure CmdQuit) idm $$ info (pure CmdQuit) idm
leftover = many (strArg "")
strArg :: String -> Parser String strArg :: String -> Parser String
strArg = argument str . metavar strArg = argument str . metavar