From 8adfffba670eeabbe2c56cf0132e8f527dc423b3 Mon Sep 17 00:00:00 2001 From: Paul Johnson Date: Sun, 10 Apr 2022 07:55:12 +0100 Subject: [PATCH 1/3] If -h or --help is given then print helpful message and exit. --- app/Main.hs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/Main.hs b/app/Main.hs index c17fa07..09ffb08 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -9,7 +9,9 @@ import Hie.Locate import Hie.Yaml import System.Directory import System.Environment +import System.Exit import System.FilePath.Posix +import System.IO main :: IO () main = do @@ -19,7 +21,7 @@ main = do "cabal" -> cabalPkgs pwd _ -> stackYamlPkgs pwd when (null cfs) $ - error $ + die $ "Used" <> name <> "\n No .cabal files found under" <> pwd @@ -31,6 +33,12 @@ resolveName :: FilePath -> IO String resolveName pwd = do args <- getArgs files <- listDirectory pwd + when ("--help" `elem` args || "-h" `elem` args) $ do + progName <- getProgName + hPutStrLn stderr $ "Usage: " <> progName <> " [ --cabal | --stack ]\n\n\ + \If neither argument is given then " <> progName <> " will infer the type by\n\ + \looking for dist-newstyle, .stack-work, cabal.project and stack.yaml in that order." + exitSuccess let fileNames = map takeFileName files name = if From c6ecccdefda42d86f962a8a0d7f33177e7554f9d Mon Sep 17 00:00:00 2001 From: Paul Johnson Date: Sun, 10 Apr 2022 07:59:36 +0100 Subject: [PATCH 2/3] Corrected format in error message. --- app/Main.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Main.hs b/app/Main.hs index 09ffb08..26d5710 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -22,7 +22,7 @@ main = do _ -> stackYamlPkgs pwd when (null cfs) $ die $ - "Used" <> name + "Used " <> name <> "\n No .cabal files found under" <> pwd <> "\n You may need to run stack build." From 0c336ba826556d78574eb21d241df026d432c762 Mon Sep 17 00:00:00 2001 From: Paul Johnson Date: Mon, 11 Apr 2022 08:25:39 +0100 Subject: [PATCH 3/3] Ormolu formatted. --- app/Main.hs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 26d5710..1fcb73e 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -35,9 +35,13 @@ resolveName pwd = do files <- listDirectory pwd when ("--help" `elem` args || "-h" `elem` args) $ do progName <- getProgName - hPutStrLn stderr $ "Usage: " <> progName <> " [ --cabal | --stack ]\n\n\ - \If neither argument is given then " <> progName <> " will infer the type by\n\ - \looking for dist-newstyle, .stack-work, cabal.project and stack.yaml in that order." + hPutStrLn stderr $ + "Usage: " <> progName + <> " [ --cabal | --stack ]\n\n\ + \If neither argument is given then " + <> progName + <> " will infer the type by\n\ + \looking for dist-newstyle, .stack-work, cabal.project and stack.yaml in that order." exitSuccess let fileNames = map takeFileName files name =