Skip to content

Commit 289359a

Browse files
Simplify Application arguments (#107)
* simplify application's command line arguments * adjust workflow application call arguments * adjust README
1 parent cded2a8 commit 289359a

4 files changed

Lines changed: 42 additions & 11 deletions

File tree

.github/actions/spelling/expect.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ hashcons
55
Leijen
66
lhs
77
libz
8+
olution
89
OSX
910
Preds
1011
rhs
1112
SChar
1213
SEmpty
1314
SText
15+
ubmission
1416
Uniplate

.github/workflows/haskell.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
run: |
5959
set -ex
6060
while IFS= read -r -d '' f; do
61-
stack run -w run.yaml "$f" "examples/solutions/$(basename "$f")"
61+
stack run -w run.yaml "$(basename "$f")" solution
6262
done < <(find examples/configs -type f -name '*.hs' -print0)
6363
set +ex
6464
env:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Now to simulate the grading process:
2121
1. Install the z3 theorem prover (`sudo apt-get install libz3-dev` or similar)
2222
1. Install [Haskell Stack](https://docs.haskellstack.org/en/stable/#__tabbed_2_1)
2323
1. Optionally set an alias for `stack run -w run.yaml`
24-
1. Execute `stack run -w run.yaml examples/configs/<Task> <examples/tasks/<Task>`
24+
1. Execute `stack run -w run.yaml <task name> <[submission|solution]>` (`solution` loads a sample solution)
2525

2626
The submission will either be rejected or accepted and feedback be printed directly into the console.
2727
Running the stack command may take a while the first time, since a lot of dependencies will have to be installed.

run-codeworld-tasks/app/Main.hs

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module Main where
66
import qualified Data.Text as T
77
import qualified Data.Text.Lazy as LT
88

9+
import Control.Monad (void)
910
import Data.Text (Text)
1011
import Data.Text.Lazy.Builder (toLazyText)
1112
import Haskell.Template.Task (grade)
@@ -29,9 +30,12 @@ import Rainbow (
2930
import System.Directory (getTemporaryDirectory)
3031
import System.Exit (die, exitFailure, exitSuccess)
3132
import System.Environment (getArgs)
32-
import System.FilePath ((-<.>))
33+
import System.FilePath ((</>), (-<.>))
3334
import System.IO (readFile')
35+
import Text.ParserCombinators.ReadP ((+++), char, choice, string)
36+
import Text.ParserCombinators.ReadPrec (lift)
3437
import Text.PrettyPrint.Leijen.Text (Doc, SimpleDoc(..), renderPretty)
38+
import Text.Read (Read(..), readMaybe)
3539

3640

3741

@@ -53,16 +57,32 @@ suggestionStyle :: Text -> Chunk
5357
suggestionStyle = bold . fore brightYellow . chunk
5458

5559

60+
data Mode = Submission | Solution
61+
62+
63+
instance Read Mode where
64+
readPrec = lift $ do
65+
void $ char 's' +++ char 'S'
66+
choice [
67+
string "ubmission" >> pure Submission,
68+
string "olution" >> pure Solution
69+
]
70+
71+
5672
main :: IO ()
5773
main = do
5874
args <- getArgs
5975
case args of
60-
[task,submission] -> do
61-
taskContents <- openDotHs task
62-
submissionContents <- openDotHs submission
63-
runTemplateTask taskContents submissionContents
64-
exitSuccess
65-
_ -> die usage
76+
[task,subMode] -> do
77+
let openFileInDir dir = openDotHs $ "examples" </> dir </> task
78+
taskContents <- openFileInDir "configs"
79+
submissionContents <- maybe
80+
modeHelp
81+
(openFileInDir . modeToDir)
82+
$ readMaybe subMode
83+
runTemplateTask taskContents submissionContents
84+
exitSuccess
85+
_ -> usage
6686

6787

6888
runTemplateTask :: String -> String -> IO ()
@@ -80,12 +100,21 @@ runTemplateTask task submission = do
80100
putChunkLn $ statusLabel green "SUCCESS"
81101

82102

103+
modeToDir :: Mode -> FilePath
104+
modeToDir Submission = "tasks"
105+
modeToDir Solution = "solutions"
106+
107+
83108
openDotHs :: FilePath -> IO String
84109
openDotHs path = readFile' $ path -<.> "hs"
85110

86111

87-
usage :: String
88-
usage = "usage: test-task <config path> <solution path>"
112+
modeHelp :: IO a
113+
modeHelp = die "Parse error on submission mode. Try 'submission' or 'solution'"
114+
115+
116+
usage :: IO a
117+
usage = die "usage: test-task <task name> <[submission|solution]>"
89118

90119

91120
styleRejections :: Text -> Chunk

0 commit comments

Comments
 (0)