Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add interpreter command to print current working directory #1769

Merged
merged 4 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions intTests/test_pwd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Test the REPL's `:pwd` command. This test will pass if the REPL output of this
command includes, in any position, the current working directory as rendered by
`bash`'s `pwd`.
7 changes: 7 additions & 0 deletions intTests/test_pwd/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -e

HERE=`pwd`
RES=`echo ':pwd' | $SAW --interactive --no-color`
[[ "$RES" =~ .*"$HERE".* ]]
7 changes: 6 additions & 1 deletion saw/SAWScript/REPL/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import Data.Char (isSpace,isPunctuation,isSymbol)
import Data.Function (on)
import Data.List (intercalate)
import System.FilePath((</>), isPathSeparator)
import System.Directory(getHomeDirectory,setCurrentDirectory,doesDirectoryExist)
import System.Directory(getHomeDirectory,getCurrentDirectory,setCurrentDirectory,doesDirectoryExist)
import qualified Data.Map as Map

-- SAWScript imports
Expand Down Expand Up @@ -124,6 +124,8 @@ commandList =
"exit the REPL"
, CommandDescr ":cd" (FilenameArg cdCmd)
"set the current working directory"
, CommandDescr ":pwd" (NoArg pwdCmd)
"display the current working directory"
]

genHelp :: [CommandDescr] -> [String]
Expand Down Expand Up @@ -194,6 +196,9 @@ cdCmd f | null f = io $ putStrLn $ "[error] :cd requires a path argument"
then io $ setCurrentDirectory f
else raise $ DirectoryNotFound f

pwdCmd :: REPL ()
pwdCmd = io $ getCurrentDirectory >>= putStrLn

-- SAWScript commands ----------------------------------------------------------

{- Evaluation is fairly straightforward; however, there are a few important
Expand Down