From 2c9a03ce49ffdfbdbc46823cdadd6576ff045d76 Mon Sep 17 00:00:00 2001 From: Rob Dockins Date: Sat, 22 Aug 2020 15:37:07 -0700 Subject: [PATCH] Add a :version command that prints the version. Fixes #859 --- src/Cryptol/REPL/Command.hs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Cryptol/REPL/Command.hs b/src/Cryptol/REPL/Command.hs index 56f0cd3f3..5c355286d 100644 --- a/src/Cryptol/REPL/Command.hs +++ b/src/Cryptol/REPL/Command.hs @@ -88,6 +88,7 @@ import Cryptol.Symbolic ) import qualified Cryptol.Symbolic.SBV as SBV import qualified Cryptol.Symbolic.What4 as W4 +import Cryptol.Version (commitShortHash,commitDirty,version) import qualified Control.Exception as X import Control.Monad hiding (mapM, mapM) @@ -101,6 +102,7 @@ import Data.Function (on) import Data.List (intercalate, nub, sortBy, groupBy, partition, isPrefixOf,intersperse) import Data.Maybe (fromMaybe,mapMaybe,isNothing) +import Data.Version (showVersion) import System.Environment (lookupEnv) import System.Exit (ExitCode(ExitSuccess)) import System.Process (shell,createProcess,waitForProcess) @@ -194,6 +196,9 @@ nbCommandList = , CommandDescr [ ":b", ":browse" ] ["[ MODULE ]"] (ModNameArg browseCmd) "Display environment for all loaded modules, or for a specific module." "" + , CommandDescr [ ":version"] [] (NoArg versionCmd) + "Display the version of this Cryptol executable" + "" , CommandDescr [ ":?", ":help" ] ["[ TOPIC ]"] (HelpArg helpCmd) "Display a brief description of a function, type, or command. (e.g. :help :help)" (unlines @@ -1068,10 +1073,17 @@ loadHelper how = M.InMem {} -> clearEditPath setDynEnv mempty +versionCmd :: REPL () +versionCmd = rPutStrLn versionText + where + hashText | commitShortHash == "UNKNOWN" = "" + | otherwise = " (" ++ commitShortHash ++ + (if commitDirty then ", modified)" else ")") + versionText = "version " ++ showVersion version ++ hashText + quitCmd :: REPL () quitCmd = stop - browseCmd :: String -> REPL () browseCmd input = do let mnames = map (M.textToModName . T.pack) (words input)