diff --git a/src/Propellor/CmdLine.hs b/src/Propellor/CmdLine.hs index b6dd2bc..c4a3afe 100644 --- a/src/Propellor/CmdLine.hs +++ b/src/Propellor/CmdLine.hs @@ -76,7 +76,7 @@ defaultMain hostlist = do go _ (Set field context) = setPrivData field context go _ (Dump field context) = dumpPrivData field context go _ (Edit field context) = editPrivData field context - go _ ListFields = listPrivDataFields + go _ ListFields = listPrivDataFields hostlist go _ (AddKey keyid) = addKey keyid go _ (Chain hn) = withhost hn $ \h -> do r <- runPropellor h $ ensureProperties $ hostProperties h diff --git a/src/Propellor/PrivData.hs b/src/Propellor/PrivData.hs index 10965fe..27d4992 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