summaryrefslogtreecommitdiff
path: root/src/Propellor/PrivData.hs
diff options
context:
space:
mode:
authorJoey Hess2014-07-06 16:44:13 -0400
committerJoey Hess2014-07-06 16:46:00 -0400
commit20df4170b096a92a038ed8fb6fc6d44f71c42f0e (patch)
tree64d0960b17bc1fca074d6f26ab0e92e36afbfc29 /src/Propellor/PrivData.hs
parent5002b5e3915890542286487efb852c16c0ca988d (diff)
beautiful table for --list-fields, with the hostnames
Diffstat (limited to 'src/Propellor/PrivData.hs')
-rw-r--r--src/Propellor/PrivData.hs16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/Propellor/PrivData.hs b/src/Propellor/PrivData.hs
index 10965fe3..27d49926 100644
--- a/src/Propellor/PrivData.hs
+++ b/src/Propellor/PrivData.hs
@@ -8,6 +8,7 @@ import System.IO
import System.Directory
import Data.Maybe
import Data.Monoid
+import Data.List
import Control.Monad
import Control.Monad.IfElse
import "mtl" Control.Monad.Reader
@@ -88,20 +89,23 @@ editPrivData field context = do
readFile f
setPrivDataTo field context v'
-listPrivDataFields :: IO ()
-listPrivDataFields = do
+listPrivDataFields :: [Host] -> IO ()
+listPrivDataFields hosts = do
m <- decryptPrivData
putStrLn "\n"
- let rows = map mkrow (M.keys m)
+ let usedby = M.unionsWith (++) $ map mkhostmap hosts
+ let rows = map (mkrow usedby) (M.keys m)
let table = tableWithHeader header rows
putStr $ unlines $ formatTable table
where
- header = ["Field", "Context", "Hosts"]
- mkrow (field, (Context context)) =
+ header = ["Field", "Context", "Used by"]
+ mkrow usedby k@(field, (Context context)) =
[ shellEscape $ show field
, shellEscape context
- , "xxx"
+ , intercalate ", " $ sort $ fromMaybe [] $ M.lookup k usedby
]
+ mkhostmap host = M.fromList $ map (\k -> (k, [hostName host])) $
+ S.toList $ _privDataFields $ hostInfo host
setPrivDataTo :: PrivDataField -> Context -> PrivData -> IO ()
setPrivDataTo field context value = do