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
pargs <- maybe (throw $ InvalidCommandLine $ Left cmdArg) return
$ parseArgsInteractive cmdArg
case fst pargs of
case pargs of
CmdFind symbol ->
lookupSymbol symbol =<< checkDb symdbreq =<< getDb symdbreq

View File

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

View File

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