From 886743421aed9bf61ac01cbff2364db58b96486d Mon Sep 17 00:00:00 2001 From: mbays Date: Thu, 6 Jul 2023 00:00:00 +0000 Subject: [PATCH] correctly handle empty input with -f --- diohsc.hs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/diohsc.hs b/diohsc.hs index f0aea0d..52b8bcd 100644 --- a/diohsc.hs +++ b/diohsc.hs @@ -12,6 +12,7 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TupleSections #-} module Main where @@ -20,6 +21,7 @@ import Control.Monad.State import Data.Hashable (hash) import Data.Maybe +import Data.Semigroup (Any (..)) import qualified Data.Set as S import qualified Data.Text.Lazy as T import qualified Data.Text.Lazy.IO as T @@ -65,13 +67,15 @@ main = do outTerm <- hIsTerminalDevice stdout let ansi = NoAnsi `notElem` opts && (outTerm || Ansi `elem` opts) - let argCommands (ScriptFile "-") = warnIOErrAlt $ + let argCommands :: Opt -> IO (Any, [String]) + argCommands (ScriptFile "-") = ((Any True,) <$>) . warnIOErrAlt $ (T.unpack . T.strip <$>) . T.lines <$> T.getContents - argCommands (ScriptFile f) = warnIOErrAlt $ (T.unpack <$>) <$> readFileLines f - argCommands (OptCommand c) = return [c] - argCommands _ = return [] - optCommands <- concat <$> mapM argCommands opts - let repl = (null optCommands && Batch `notElem` opts) || Prompt `elem` opts + argCommands (ScriptFile f) = ((Any True,) <$>) . warnIOErrAlt $ + (T.unpack <$>) <$> readFileLines f + argCommands (OptCommand c) = return (Any True, [c]) + argCommands _ = return (Any False, []) + (Any commandsInOpts, optCommands) <- mconcat <$> mapM argCommands opts + let repl = (not commandsInOpts && Batch `notElem` opts) || Prompt `elem` opts let interactive = Batch `notElem` opts && (repl || Interactive `elem` opts) let argToUri arg = doesPathExist arg >>= \case -- 2.11.4.GIT