on master help sign in
Merge pull request #3632 from RyanGlScott/master

Add :! for running shell commands from the REPL

commit735fbd21eae2c2b79b757ad68b4cbbbfc592fcd0 authorNiklas Larsson <metaniklas@gmail.com> dateFri 27 Jan 2017, 01:04 (10 years ago) parent9b2821183cf2f6
6 files changed+10
CHANGELOG.md+2 src/Idris/Completion.hs+1 src/Idris/Help.hs+2 src/Idris/REPL.hs+3 src/Idris/REPL/Commands.hs+1 src/Idris/REPL/Parser.hs+1
CHANGELOG.md+2
@@ -27,6 +27,8 @@
2727 `--V0`, `--V1`, and `--V2`. The old aliases of `-V` and `--verbose`
2828 persist.
2929
30++ New REPL command `:!` that runs an external shell command.
31+
3032## Library Updates
3133
3234+ Terminating programs has been improved with more appropriate
src/Idris/Completion.hs+1
@@ -159,6 +159,7 @@ completeColour (prev, next) = case words (reverse prev) of
159159completeCmd :: String -> CompletionFunc Idris
160160completeCmd cmd (prev, next) = fromMaybe completeCmdName $ fmap completeArg $ lookupInHelp cmd
161161 where completeArg FileArg = completeFilename (prev, next)
162+ completeArg ShellCommandArg = completeFilename (prev, next)
162163 completeArg NameArg = completeName UpTo [] (prev, next)
163164 completeArg OptionArg = completeOption (prev, next)
164165 completeArg ModuleArg = noCompletion (prev, next)
src/Idris/Help.hs+2
@@ -11,6 +11,7 @@ module Idris.Help (CmdArg(..), extraHelp) where
1111data CmdArg = ExprArg -- ^ The command takes an expression
1212 | NameArg -- ^ The command takes a name
1313 | FileArg -- ^ The command takes a file
14+ | ShellCommandArg -- ^ The command takes a shell command name
1415 | ModuleArg -- ^ The command takes a module name
1516 | PkgArgs -- ^ The command takes a list of package names
1617 | NumberArg -- ^ The command takes a number
@@ -30,6 +31,7 @@ instance Show CmdArg where
3031 show ExprArg = "<expr>"
3132 show NameArg = "<name>"
3233 show FileArg = "<filename>"
34+ show ShellCommandArg = "<command>"
3335 show ModuleArg = "<module>"
3436 show PkgArgs = "<package list>"
3537 show NumberArg = "<number>"
src/Idris/REPL.hs+3
@@ -590,6 +590,8 @@ splitName s = case reverse $ splitOn "." s of
590590idemodeProcess :: FilePath -> Command -> Idris ()
591591idemodeProcess fn Warranty = process fn Warranty
592592idemodeProcess fn Help = process fn Help
593+idemodeProcess fn (RunShellCommand cmd) =
594+ iPrintError ":! is not currently supported in IDE mode."
593595idemodeProcess fn (ChangeDirectory f) =
594596 do process fn (ChangeDirectory f)
595597 dir <- runIO $ getCurrentDirectory
@@ -817,6 +819,7 @@ insertScript prf (x : xs) = x : insertScript prf xs
817819process :: FilePath -> Command -> Idris ()
818820process fn Help = iPrintResult displayHelp
819821process fn Warranty = iPrintResult warranty
822+process fn (RunShellCommand cmd) = runIO $ system cmd >> return ()
820823process fn (ChangeDirectory f)
821824 = do runIO $ setCurrentDirectory f
822825 return ()
src/Idris/REPL/Commands.hs+1
@@ -17,6 +17,7 @@ data Command = Quit
1717 | Reload
1818 | Watch
1919 | Load FilePath (Maybe Int) -- up to maximum line number
20+ | RunShellCommand FilePath
2021 | ChangeDirectory FilePath
2122 | ModImport String
2223 | Edit
src/Idris/REPL/Parser.hs+1
@@ -78,6 +78,7 @@ parserCommandsForHelp =
7878 , noArgCmd ["w", "watch"] Watch "Watch the current file for changes"
7979 , (["l", "load"], FileArg, "Load a new file"
8080 , strArg (\f -> Load f Nothing))
81+ , (["!"], ShellCommandArg, "Run a shell command", strArg RunShellCommand)
8182 , (["cd"], FileArg, "Change working directory"
8283 , strArg ChangeDirectory)
8384 , (["module"], ModuleArg, "Import an extra module", moduleArg ModImport) -- NOTE: dragons