From a9439b66ad8f7a8f4ba079a47ecfe1e76c2abc4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Fri, 4 Sep 2026 19:25:09 +0200 Subject: Expression expansion for shell arguments Changelog: Lists can now be dollar-expanded in the shell interpreter to provide list of shell command arguments. --- src/Script/Shell.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/Script') diff --git a/src/Script/Shell.hs b/src/Script/Shell.hs index 3e98e66..e7c8542 100644 --- a/src/Script/Shell.hs +++ b/src/Script/Shell.hs @@ -15,8 +15,10 @@ import Control.Monad.IO.Class import Control.Monad.Reader import Data.Maybe +import Data.Scientific import Data.Text (Text) import Data.Text qualified as T +import Data.Typeable import Foreign.C.Types import Foreign.Ptr @@ -67,6 +69,7 @@ data ShellCommand = ShellCommand } newtype ShellArguments = ShellArguments { fromShellArguments :: [ ShellArgument ] } + deriving (Semigroup, Monoid) data ShellArgument = ShellArgument Text @@ -97,10 +100,25 @@ instance ExprType ShellArguments where textExprType _ = T.pack "ShellArguments" textExprValue _ = "" + exprExpansionConvFrom = listToMaybe $ catMaybes + [ cast (ShellArguments . (: []) . ShellArgument) + , cast (ShellArguments . (: []) . ShellArgument . T.pack . show @Integer) + , cast (ShellArguments . (: []) . ShellArgument . T.pack . show @Scientific) + , cast (ShellArguments . map ShellArgument) + , cast (ShellArguments . map (ShellArgument . T.pack . show @Integer)) + , cast (ShellArguments . map (ShellArgument . T.pack . show @Scientific)) + ] + instance ExprType ShellArgument where textExprType _ = T.pack "ShellArgument" textExprValue _ = "" + exprExpansionConvFrom = listToMaybe $ catMaybes + [ cast (ShellArgument) + , cast (ShellArgument . T.pack . show @Integer) + , cast (ShellArgument . T.pack . show @Scientific) + ] + data ShellExecInfo = ShellExecInfo { seiNode :: Node -- cgit v1.2.3