From 544bf574297b5bcca765e9f495a6bace9d9866cd Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Wed, 10 Apr 2024 19:24:51 -0400 Subject: Report cli errors on run This is mostly helpful when debugging or writing programs, not during usage, but I shouldn't be suppressing errors anyway. My first version of this patch used `Biz.Log` instead of `panic`. Unfortunately this exposed a bug in bild: Control/Concurrent/Go.hs (and others) failed to build because it imported `Biz.Cli` which imported `Biz.Log`, and bild couldn't find `Biz/Log.hs`. So apparently my function `detectHaskellImports` doesn't detect all Haskell imports, somewhere along the lines I cut the graph short instead of recursing. I guess that will be a project for another day. --- Biz/Cli.hs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'Biz') diff --git a/Biz/Cli.hs b/Biz/Cli.hs index b3c7583..5029792 100644 --- a/Biz/Cli.hs +++ b/Biz/Cli.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE NoImplicitPrelude #-} @@ -33,14 +35,16 @@ data Plan cfg = Plan main :: Plan cfg -> IO () main Plan {..} = Environment.getArgs - +> Docopt.parseArgsOrExit help - +> \args -> - if args `has` Docopt.command "test" - then Test.run test - else - if args `has` Docopt.longOption "help" || args `has` Docopt.shortOption 'h' - then Docopt.exitWithUsage help - else move args + /> Docopt.parseArgs help + +> \case + Left err -> panic <| show err + Right args -> + if args `has` Docopt.command "test" + then Test.run test + else + if args `has` Docopt.longOption "help" || args `has` Docopt.shortOption 'h' + then Docopt.exitWithUsage help + else move args has :: Docopt.Arguments -> Docopt.Option -> Bool has = Docopt.isPresent -- cgit v1.2.3