Skip to content

Commit

Permalink
Set stack working dir and refactor CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
matthunz committed Jun 16, 2024
1 parent 944c3b9 commit 7466513
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import GHC.IO.Exception (ExitCode (ExitSuccess))
import Options.Applicative
import System.Environment.XDG.BaseDir (getUserConfigDir, getUserDataDir)
import System.FilePath ((</>))
import System.Process (readProcessWithExitCode)
import System.Process (cwd, proc, readCreateProcessWithExitCode, readProcessWithExitCode)

data Args = Args
newtype Args = Args
{aRecompile :: Bool}

args :: Parser Args
Expand All @@ -33,9 +33,11 @@ appName :: String
appName = "prompt"

run :: Args -> IO ()
run args = do
when (aRecompile args) recompile
run (Args True) = recompile
run (Args False) = prompt

prompt :: IO ()
prompt = do
dataDir <- getUserDataDir ""
let binPath = dataDir </> appName

Expand All @@ -57,17 +59,14 @@ recompile = do
configDir <- getUserConfigDir ""

let binPath = dataDir </> appName
let appConfigDir = configDir </> "prompt"

result <-
try
( readProcessWithExitCode
"stack"
[ "ghc",
"--",
"-o",
binPath,
configDir </> "prompt" </> "config.hs"
]
( readCreateProcessWithExitCode
(proc "stack" ["ghc", "--", "-o", binPath, appConfigDir </> "config.hs"])
{ cwd = Just appConfigDir
}
""
) ::
IO (Either SomeException (ExitCode, String, String))
Expand Down

0 comments on commit 7466513

Please sign in to comment.