#!/usr/bin/env stack --stack --install-ghc runghc module Version (my_version) where import System.Environment import System.Exit import System.Process -- | Read current package version -- -- Example: -- -- >>> putStrLn $ my_version -- 0.2.1.7 -- --my_version :: IO ([Char]) --my_version = do -- let stdin' = "" -- (errCode, stdout', stderr') <- readProcessWithExitCode "./get_version" [""] stdin' -- return stdout' -- --my_version' :: IO () --my_version' = putStr $ my_version -- get_version = my_version -- -- show_all = map putStr -- -- exit = exitWith ExitSuccess -- -- all_file = my_version >>= putStr --main = my_version >>= lines >>= unlines >>= putStr --main = show_all $ get_version -- putStrLn . show $ (!!) a 1 -- See http://learnyouahaskell.com/input-and-output --my_version :: IO String --my_version = readFile "package.yaml" -- --firstLine :: String -> String --firstLine = head . lines -- --first_line_of_file = firstLine $ my_version -- Worked! --my_version = do -- contents <- readFile "package.yaml" -- let version_line = lines contents !! 1 -- let version_word = words version_line !! 1 -- return version_word my_version :: FilePath -> IO String my_version file_name = do contents <- readFile file_name let version_line = lines contents !! 1 let version_word = words version_line !! 1 return version_word main :: IO () main = my_version "package.yaml" >>= putStrLn :: IO ()