gregwebs/Shelly.hs

Export State(..) from Shelly

Opened this issue · 2 comments

Hi. I'm trying to write some simpler wrappers around native Shelly behavior, namely to have errExit True functionality, but without printing stack traces. It's a pretty simple wrap around runing commands, but it requires me to check the current state, something like:

-- | A version of Shelly's 'run' that avoids printing out a stack trace on error
run' :: FilePath -> [T.Text] -> Sh T.Text
run' fp args = do
  e    <- sErrExit <$> get
  stdo <- errExit False $ run fp args
  ex   <- lastExitCode
  if e && ex > 0
    then lastStdErr >>= errorExit'
    else return stdo

-- | A version of Shelly's 'errorExit' without debug information
errorExit' :: T.Text -> Sh a
errorExit' err = echo_err err >> quietExit 1

The problem is, State(..) is not exported from any exposed modules, so we have no way to deconstruct the a value of type State. Or more simply, in this example, I don't have access to sErrExit.

I see that you exported both get and set but these are useless without being able to access values in the return value of get. What are your thoughts? Is there a reason these are not exported?

I am quite open to exporting everything under an Internal module. State has always been treated as something that is not an interface, the interface approach would probably be to create a specific getter or settter.

e4z9 commented

I just wondered about the same, since I wanted my custom command to take the sFollowSymlink property into account. Saw that get is exported, and wondered what to do with it.