language-puppet 1.3 → 1.3.1
raw patch · 5 files changed
+66/−28 lines, 5 filesdep ~http-api-data
Dependency ranges changed: http-api-data
Files
- CHANGELOG.markdown +6/−1
- README.adoc +8/−0
- language-puppet.cabal +2/−2
- progs/PuppetResources.hs +9/−1
- progs/pdbQuery.hs +41/−24
CHANGELOG.markdown view
@@ -1,4 +1,9 @@-#v1.3 (2016/07/11)+# v1.3.1 (2016/08/31)++* Add `--version` to puppetresources and pdbquery+* Version bump for some dependencies++# v1.3 (2016/07/11) This release is about dependencies versions upgrades.
README.adoc view
@@ -116,6 +116,10 @@ Enable `parse mode`. Specify the puppet file to be parsed. Variables are not resolved. No interpretation. +`--version`::++Output version information and exist.+ === Settings defaults using a yaml file Defaults for some of these options can be set using a `/yourworkingdirectory/tests/defaults.yaml` file. For instance `OptionalTests` is checking that all users and groups are known. Because some of these users and groups might be defined outside puppet, a list of known ones is used internally. This can be overridden in that file using the key `knownusers` and `knowngroups`.@@ -155,6 +159,10 @@ `addfacts`:: Adds facts to the test DB for the given node name, if they are not already defined.++`--version`::++Output version information and exit. == Unsupported Puppet idioms or features
language-puppet.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: language-puppet-version: 1.3+version: 1.3.1 synopsis: Tools to parse and evaluate the Puppet DSL. description: This is a set of tools that is supposed to fill all your Puppet needs : syntax checks, catalog compilation, PuppetDB queries, simulationg of complex interactions between nodes, Puppet master replacement, and more ! homepage: http://lpuppet.banquise.net/@@ -97,7 +97,7 @@ , filecache >= 0.2.9 && < 0.3 , formatting , hashable == 1.2.*- , http-api-data == 0.2.*+ , http-api-data >= 0.2 && < 0.4 , http-client >= 0.5 && < 0.6 , hruby >= 0.3.2 && < 0.4 , hslogger == 1.2.*
progs/PuppetResources.hs view
@@ -22,8 +22,10 @@ import Data.Text.Strict.Lens import Data.Tuple (swap) import qualified Data.Vector as V+import qualified Data.Version (showVersion) import Network.HTTP.Client import Options.Applicative+import qualified Paths_language_puppet import Servant.Common.BaseUrl (parseBaseUrl) import System.Exit (exitFailure, exitSuccess) import qualified System.FilePath.Glob as G@@ -45,7 +47,6 @@ import PuppetDB.Remote (pdbConnect) import PuppetDB.TestDB (loadTestDB) - type ParseError' = P.ParseError Char P.Dec type QueryFunc = NodeName -> IO (S.Either PrettyError (FinalCatalog, EdgeMap, FinalCatalog, [Resource])) @@ -75,6 +76,7 @@ , _optParse :: Maybe FilePath , _optStrictMode :: Bool , _optNoExtraTests :: Bool+ , _optVersion :: Bool } deriving (Show) options :: Parser Options@@ -144,6 +146,9 @@ <*> flag False True ( long "noextratests" <> help "Disable extra tests (eg.: check that files exist on local disk")+ <*> switch+ ( long "version"+ <> help "Output version information and exit") -- | Like catMaybes, but it counts the Nothing values@@ -360,7 +365,10 @@ Right Nothing -> return False _ -> return True + run :: Options -> IO ()+run Options {_optVersion = True, ..} = putStrLn ("language-puppet " ++ Data.Version.showVersion Paths_language_puppet.version)+ -- | Parse mode run Options {_optParse = Just fp, ..} = parseFile fp >>= \case Left rr -> error ("parse error:" ++ show rr)
progs/pdbQuery.hs view
@@ -1,32 +1,37 @@-{-# LANGUAGE LambdaCase #-}-{-# LANGUAGE GADTs #-}+{-# LANGUAGE GADTs #-}+{-# LANGUAGE LambdaCase #-} {-# LANGUAGE RecordWildCards #-} module Main where -import Puppet.Interpreter.Types-import PuppetDB.Common-import PuppetDB.TestDB-import PuppetDB.Remote-import Facter- import Control.Lens-import Control.Monad (forM_,unless,(>=>))+import Control.Monad (forM_, unless, (>=>)) import Control.Monad.Trans.Except-import qualified Data.ByteString.Char8 as BS-import qualified Data.Either.Strict as S-import qualified Data.HashMap.Strict as HM-import Data.List (foldl')+import qualified Data.ByteString.Char8 as BS+import qualified Data.Either.Strict as S+import qualified Data.HashMap.Strict as HM+import Data.List (foldl') import Data.Monoid-import qualified Data.Text as T-import qualified Data.Vector as V-import Data.Yaml hiding (Parser)+import qualified Data.Text as T+import qualified Data.Vector as V+import qualified Data.Version (showVersion)+import Data.Yaml hiding (Parser) import Network.HTTP.Client-import Options.Applicative as O+import Options.Applicative as O+import qualified Paths_language_puppet import Servant.Common.BaseUrl+import System.Exit (exitFailure) -data Options = Options { _pdbloc :: Maybe FilePath- , _pdbtype :: PDBType- , _pdbcmd :: Command+import Facter+import Puppet.Interpreter.Types+import PuppetDB.Common+import PuppetDB.Remote+import PuppetDB.TestDB+++data Options = Options { _pdbloc :: Maybe FilePath+ , _pdbtype :: PDBType+ , _pdbcmd :: Maybe Command+ , _pdbversion :: Bool } data Command = DumpFacts@@ -49,7 +54,11 @@ <> short 't' <> value PDBTest <> help "PuppetDB types : test, remote, dummy")- <*> cmd+ <*> optional cmd++ <*> switch+ ( long "version"+ <> help "Output version information and exit") where cmd = subparser ( command "dumpfacts" (info (pure DumpFacts)(progDesc "Dump all facts, store in /tmp/allfacts.yaml" <> failureCode 4)) <> command "editfact" (info factedit (progDesc "Edit a fact corresponding to a node" <> failureCode 7 ))@@ -91,17 +100,25 @@ runCheck :: Show r => String -> ExceptT r IO a -> IO a runCheck s = runExceptT >=> checkError s +showHelpText :: ParserPrefs -> ParserInfo a -> IO ()+showHelpText pprefs pinfo = handleParseResult . Failure $+ parserFailure pprefs pinfo ShowHelpText mempty+ run :: Options -> IO ()-run Options{..} = do+run Options {_pdbversion = False, _pdbcmd = Nothing} =+ putStrLn "Please provide one of the available command (see --help for more information) " *> exitFailure+run Options {_pdbversion = True, ..} = putStrLn ("language-puppet " ++ Data.Version.showVersion Paths_language_puppet.version)++run Options{_pdbcmd = Just pdbcmd, ..} = do mgr <- newManager defaultManagerSettings epdbapi <- case (_pdbloc, _pdbtype) of (Just l, PDBRemote) -> pdbConnect mgr $ either (error . show) id $ parseBaseUrl l (Just l, PDBTest) -> loadTestDB l (_, x) -> getDefaultDB x pdbapi <- case epdbapi of- Left r -> error (show r)+ Left r -> error (show r) Right x -> return x- case _pdbcmd of+ case pdbcmd of DumpFacts -> if _pdbtype == PDBDummy then puppetDBFacts "dummy" pdbapi >>= mapM_ print . HM.toList else do