diff options
| author | Joey Hess <joey@kitenet.net> | 2014-07-06 16:44:13 -0400 |
|---|---|---|
| committer | Joey Hess <joey@kitenet.net> | 2014-07-06 16:46:00 -0400 |
| commit | 20df4170b096a92a038ed8fb6fc6d44f71c42f0e (patch) | |
| tree | 64d0960b17bc1fca074d6f26ab0e92e36afbfc29 /src/Propellor | |
| parent | 5002b5e3915890542286487efb852c16c0ca988d (diff) | |
beautiful table for --list-fields, with the hostnames
Diffstat (limited to 'src/Propellor')
| -rw-r--r-- | src/Propellor/CmdLine.hs | 2 | ||||
| -rw-r--r-- | src/Propellor/PrivData.hs | 16 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/Propellor/CmdLine.hs b/src/Propellor/CmdLine.hs index b6dd2bc1..c4a3afec 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 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 |
