Commit f101a822 authored by Ben Gamari's avatar Ben Gamari Committed by Ben Gamari

ghci: Refactor handling of :show

In so doing ensure that the help text can't fall out of sync with the
implementation.

Test Plan: Validate and play in ghci

Reviewers: austin, thomie

Reviewed By: austin, thomie

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D1538

GHC Trac Issues: #11111
parent 58972131
......@@ -2333,27 +2333,45 @@ showCmd :: String -> GHCi ()
showCmd "" = showOptions False
showCmd "-a" = showOptions True
showCmd str = do
st <- getGHCiState
case words str of
["args"] -> liftIO $ putStrLn (show (GhciMonad.args st))
["prog"] -> liftIO $ putStrLn (show (progname st))
["editor"] -> liftIO $ putStrLn (show (editor st))
["stop"] -> liftIO $ putStrLn (show (stop st))
["imports"] -> showImports
["modules" ] -> showModules
["bindings"] -> showBindings
["linker"] ->
do dflags <- getDynFlags
liftIO $ showLinkerState dflags
["breaks"] -> showBkptTable
["context"] -> showContext
["packages"] -> showPackages
["paths"] -> showPaths
["languages"] -> showLanguages -- backwards compat
["language"] -> showLanguages
["lang"] -> showLanguages -- useful abbreviation
_ -> throwGhcException (CmdLineError ("syntax: :show [ args | prog | editor | stop | modules\n" ++
" | bindings | breaks | context | packages | language ]"))
st <- getGHCiState
dflags <- getDynFlags
let lookupCmd :: String -> Maybe (GHCi ())
lookupCmd name = lookup name $ map (\(_,b,c) -> (b,c)) cmds
-- (show in help?, command name, action)
action :: String -> GHCi () -> (Bool, String, GHCi ())
action name m = (True, name, m)
hidden :: String -> GHCi () -> (Bool, String, GHCi ())
hidden name m = (False, name, m)
cmds =
[ action "args" $ liftIO $ putStrLn (show (GhciMonad.args st))
, action "prog" $ liftIO $ putStrLn (show (progname st))
, action "editor" $ liftIO $ putStrLn (show (editor st))
, action "stop" $ liftIO $ putStrLn (show (stop st))
, action "imports" $ showImports
, action "modules" $ showModules
, action "bindings" $ showBindings
, action "linker" $ getDynFlags >>= liftIO . showLinkerState
, action "breaks" $ showBkptTable
, action "context" $ showContext
, action "packages" $ showPackages
, action "paths" $ showPaths
, action "language" $ showLanguages
, hidden "languages" $ showLanguages -- backwards compat
, hidden "lang" $ showLanguages -- useful abbreviation
]
case words str of
[w] | Just action <- lookupCmd w -> action
_ -> let helpCmds = [ text name | (True, name, _) <- cmds ]
in throwGhcException $ CmdLineError $ showSDoc dflags
$ hang (text "syntax:") 4
$ hang (text ":show") 6
$ brackets (fsep $ punctuate (text " |") helpCmds)
showiCmd :: String -> GHCi ()
showiCmd str = do
......
Markdown is supported
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