stack-run 0.1.0.7 → 0.1.1.0
raw patch · 2 files changed
+33/−1 lines, 2 filesdep +questionerdep +stmdep +terminal-size
Dependencies added: questioner, stm, terminal-size, vty
Files
- src/Main.hs +28/−0
- stack-run.cabal +5/−1
src/Main.hs view
@@ -16,6 +16,7 @@ import Distribution.PackageDescription import Distribution.PackageDescription.Parse import System.Console.ANSI+import System.Console.Questioner import System.Directory import System.Directory.ProjectRoot import System.Environment@@ -35,6 +36,9 @@ , "" , " stack run set-default <name> Sets the default executable to run" , ""+ , " stack run --interactive Runs in interactive mode"+ , " stack run -i"+ , "" , " stack run help Print this help message" , " stack run --help" , " stack run -h"@@ -67,6 +71,22 @@ [] -> error "No executable found" ((d, _):_) -> return d +getExecutables :: IO [String]+getExecutables = do+ pr <- fromMaybe (error "No project root found") <$>+ getProjectRootCurrent+ cfp <- fromMaybe (error "No cabal file found") <$>+ (find ((== ".cabal") . takeExtension) <$> getDirectoryContents pr)+ pkgParseResult <- getPackageDescription (pr </> cfp)+ return $ getExecutables pkgParseResult+ where+ getPackageDescription p = parsePackageDescription <$> readFile p+ getExecutables (ParseFailed _) =+ error "Failed to parse cabal file"+ getExecutables (ParseOk _ gpd) = case condExecutables gpd of+ [] -> error "No executables found"+ ds -> map fst ds+ stackRun :: String -> [String] -> IO b stackRun name as = do pr <- fromMaybe (error "No project root found") <$> getProjectRootCurrent@@ -131,6 +151,12 @@ hPutStrLn stderr cmd hSetSGR stderr [Reset] +runInteractive :: [String] -> IO ()+runInteractive as = do+ exs <- getExecutables+ ex <- prompt ("What executable should we run? ", exs)+ stackRun ex as+ main :: IO () main = do args <- getArgs@@ -142,6 +168,8 @@ ("get-default":_) -> putStrLn =<< findDefault ("--help":_) -> exitUsage ("-h":_) -> exitUsage+ ("-i":as) -> runInteractive as+ ("--interactive":as) -> runInteractive as ("help":_) -> exitUsage ("--":"--":as) -> flip stackRun as =<< findDefault ("--":name:as) -> stackRun name as
stack-run.cabal view
@@ -1,5 +1,5 @@ name: stack-run-version: 0.1.0.7+version: 0.1.1.0 synopsis: An equivalent to cabal run for stack. description: Finds the project root, compiles your code and runs the first or set default executable. It's a shorthand for@@ -21,6 +21,9 @@ executable stack-run main-is: Main.hs build-depends: Cabal+ , terminal-size+ , vty+ , stm , MissingH , ansi-terminal >= 0.6 , async@@ -32,6 +35,7 @@ , filepath , projectroot >= 0.2 , time >= 1.5.0.1+ , questioner hs-source-dirs: src default-language: Haskell2010 ghc-options: -threaded