packages feed

runhs 1.0.0.3 → 1.0.0.4

raw patch · 3 files changed

+24/−21 lines, 3 filesnew-component:exe:runhs

Files

README.md view
@@ -19,7 +19,7 @@    * **MacOS Catalina and newer:** `echo 'export PATH="${HOME}/.local/bin:${PATH}"' >> ~/.zshrc && export PATH="${HOME}/.local/bin:${PATH}"` -3. Finally, install _runhs_: ~~`stack install runhs`.~~ Download the appropriate executable for your platform from the [Releases page](https://github.com/friedbrice/runhs/releases/).+3. Finally, install _runhs_: Download the appropriate executable for your platform from the [Releases page](https://github.com/friedbrice/runhs/releases/) and put it somewhere on your `PATH`, or `stack install runhs`.   ## Usage
runhs.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.2  name: runhs-version: 1.0.0.3+version: 1.0.0.4 synopsis: Stack wrapper for single-file Haskell programs. description:   Stack wrapper for single-file Haskell programs.@@ -21,7 +21,7 @@   type: git   location: https://github.com/friedbrice/runhs -executable runhs-exe+executable runhs   main-is: Main.hs   hs-source-dirs: src   build-depends:
src/Main.hs view
@@ -6,18 +6,17 @@   - process   - yaml -}-{-# LANGUAGE ImplicitParams, OverloadedStrings, TemplateHaskell #-}+{-# OPTIONS_GHC -Wall -fno-warn-name-shadowing #-}+{-# LANGUAGE OverloadedStrings, TemplateHaskell #-}  module Main (main) where -import Control.Monad (void) import Data.ByteString.Char8 (pack) import Data.FileEmbed (embedStringFile)-import Data.Foldable (fold, toList)-import Data.Yaml (Value, decodeThrow, parseMaybe, withObject, (.:), (.:?))-import GHC.Exception (CallStack)+import Data.Foldable (fold)+import Data.Yaml (decodeThrow, parseMaybe, withObject, (.:), (.:?)) import System.Environment (getArgs)-import System.Exit (exitWith)+import System.Exit (ExitCode(ExitFailure), exitWith) import System.IO (BufferMode(NoBuffering), hSetBuffering, stdout) import System.Process (CreateProcess, createProcess, proc, waitForProcess) @@ -38,7 +37,9 @@             . lines     header <- readHeader =<< readFile path     (resolver, packages) <--        maybe (help "spec") pure+        maybe+            (help $ "unable to parse the front matter in " <> path)+            pure         . flip parseMaybe header         . withObject "header"         $ \hdr -> do@@ -62,16 +63,16 @@         "repl":file:_ -> repl =<< spec file         "compile":file:_ -> compile =<< spec file         "script":file:args' -> script args' =<< spec file-        _ -> help "main"+        _ -> help "unable to parse the command-line arguments" -go :: CreateProcess -> IO ()-go process = do+runProcess :: CreateProcess -> IO ()+runProcess process = do     (_, _, _, h) <- createProcess process     code <- waitForProcess h     exitWith code  watch :: RunSpec -> IO ()-watch spec = go $+watch spec = runProcess $     proc "stack"         [ "exec"         , "--resolver"@@ -83,19 +84,21 @@         ]  repl :: RunSpec -> IO ()-repl spec = go $+repl spec = runProcess $     proc "stack" ("repl" : stackArgs spec)  compile :: RunSpec -> IO ()-compile spec = go $+compile spec = runProcess $     proc "stack" ("ghc" : stackArgs spec)  script :: [String] -> RunSpec -> IO ()-script args spec = go $+script args spec = runProcess $     proc "stack" ("runhaskell" : stackArgs spec <> args) -help :: (?loc :: CallStack) => String -> IO a-help trace = do+help :: String -> IO a+help reason = do+    putStrLn (replicate 40 '~')     putStrLn $(embedStringFile "README.md")-    putStrLn ""-    fail (trace <> ": " <> show ?loc)+    putStrLn (replicate 40 '~')+    putStrLn $ "runhs: " <> reason <> ". Please see ``Usage'' above."+    exitWith (ExitFailure 1)