module Propellor.Property.ZFS.Process where
import Propellor.Base
import Data.String.Utils (split)
import Data.List
zfsGetProperties :: ZFS -> IO ZFSProperties
zfsGetProperties z =
let plist = fromPropertyList . map (\(_:k:v:_) -> (k, v)) . (map (split "\t"))
in plist <$> runZfs "get" [Just "-H", Just "-p", Just "all"] z
zfsExists :: ZFS -> IO Bool
zfsExists z = any id . map (isInfixOf (zfsName z))
<$> runZfs "list" [Just "-H"] z
runZfs :: String -> [Maybe String] -> ZFS -> IO [String]
runZfs cmd args z = lines <$> uncurry readProcess (zfsCommand cmd args z)
zfsCommand :: String -> [Maybe String] -> ZFS -> (String, [String])
zfsCommand cmd args z = ("zfs", cmd:(map (maybe (zfsName z) id) args))