I need to run several commands via `sudo`. After reading Don Stewart's
["Practical Haskell Programming: Scripting With Types"][1], i think about
adding a wrapper type:
> {-# LANGUAGE RankNTypes #-}
>
> import Development.Shake
> import Development.Shake.Command
>
> data Priv = Priv (forall t. CmdArguments t => t)
which may be run using
> runPriv :: CmdArguments t => Priv -> t
> runPriv (Priv x) = cmdArguments (arg ("sudo" :: String) ++ x)
and used like
*Main> shakeArgs shakeOptions (action (unit . runPriv $ Priv (cmd "ls" ".")))
# sudo (for <unknown>)
[sudo] password for sgf:
1.cfg 1.lhs app extra-deps LICENSE Setup.hs set-wakeup.cabal src stack.yaml test
Build completed in 0:06m
but neither `arg`, nor `cmdArguments` are exported. Instead of `arg` i may
just create `Either` by hand, but i can't go ahead without `cmdArguments`,
because once i've converted `CmdArguments t => t` to `[Either CmdOption
String]` i can no longer apply `cmd` to a list (to convert back to
`CmdArguments t => t`), because (i think) ghc can't determine the number of
elements in a list at compile time.
So, what is the proper way to run privileged commands with shake?
[1]: https://donsbot.files.wordpress.com/2009/01/semicolon.pdf
--
Dmitriy Matrosov