`cmd` does not work with `String` argument
sgf-dma opened this issue · 3 comments
Hi.
cmd
does not work with String
argument, because ghc uses
ShellCmd ([arg] -> result)
instance and looks for CmdArg Char
instance.
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ExtendedDefaultRules #-} {-# OPTIONS_GHC -fno-warn-type-defaults #-} import Shelly import qualified Data.Text as T default (T.Text) -- Does not work. strCmd :: Sh () strCmd = cmd "ls" ("." :: String) -- Works as expected. strCmdL :: Sh () strCmdL = cmd "ls" ["." :: String]
fails with error
[4 of 4] Compiling Main ( 1.hs, interpreted )
1.hs:9:11: error:
• No instance for (CmdArg Char) arising from a use of ‘cmd’
• In the expression: cmd "ls" ("." :: String)
In an equation for ‘strCmd’: strCmd = cmd "ls" ("." :: String)
This may be fixed, if we make
instance CmdArg a => CmdArg [a] where
instead of
instance (CmdArg arg, ShellCmd result) => ShellCmd ([arg] -> result) where
This requires changing the type of toTextArg
too, though.
This bug bit me when upgrading shelly to 1.9. Invocations of cmd
that worked before suddenly failed.
The CHANGELOG does not mention such incompatibilities, but should!?
I ran into this as well. It's quite annoying because the docs specifically call out FilePath
arguments as a reason to use cmd
over run
.
The original branch seems to have gone by the wayside, but I have an updated branch (the solution is largely the same as @sgf-dma 's, with some tests), if the maintainers are still open to fixing this.