Giter VIP home page Giter VIP logo

kafo_parsers's Introduction

KafoParsers

This gem can parse values, validations, documentation, types, groups and conditions of parameters from your puppet modules. Only thing you have to do is provide a path to manifest file you want to be parsed.

The library is used in Kafo, which can be used to get an idea of what's possible to build on top of this library.

Currently puppet classes and types (definitions) are supported.

Installation

Add this line to your application's Gemfile:

gem 'kafo_parsers'

And then execute:

$ bundle

Or install it yourself as:

$ gem install kafo_parsers

Usage

To parse file using the best available parser, and see parsed information:

require 'kafo_parsers/parsers'
parser = KafoParsers::Parsers.find_available or fail('No parser available')
hash = parser.parse('/puppet/module/manifests/init.pp')
p hash

find_available can take a logger object that responds to #debug to log detailed reasons why each parser isn't available.

logger = Logging.logger(STDOUT)
logger.level = :debug
KafoParsers::Parsers.find_available(:logger => logger)

To load a specific parser:

require 'kafo_parsers/puppet_strings_module_parser'
hash = KafoParsers::PuppetStringsModuleParser.parse('/puppet/module/manifests/init.pp')

PuppetStringsModuleParser

Leverage puppet-strings to parse puppet manifests. This requires puppet-strings 1.2.0 or higher and may be installed either as a gem in the same environment, or in a Puppet AIO installation.

require 'kafo_parsers/puppet_strings_module_parser'
hash = KafoParsers::PuppetStringsModuleParser.parse('/puppet/module/manifests/init.pp')

Documentation syntax

RDoc syntax

Classes and defined types should be prefixed with a comment section with an RDoc block, containing a description, headings for different parameter groups and parameters laid out as shown below:

# Example class that installs Example
#
# Supports version 1 to 3.
#
# === Parameters::
#
# $foo::  Sets the value of foo in the Example config
#
# === Advanced parameters::
#
# $bar::  Sets the value of bar in the advanced config

Parameters may have multi-line descriptions and can have extra attributes defined on new lines below them. Supports:

# $foo::  Sets the value of foo in the Example config
#         condition: $bar == 'use_foo'
#         type: Optional[String]

Supports:

  • condition: an expression to determine if the parameter is used
  • type: the data type of the parameter

Used by:

  • PuppetStringsModuleParser (but deprecated, prefer YARD)

YARD syntax

Classes and defined types should be prefixed with a comment section in YARD following the Puppet Strings documentation standard, as shown below:

# Example class that installs Example
#
# Supports version 1 to 3.
#
# @param foo Sets the value of foo in the Example config
# @param bar Sets the value of bar in the advanced config
#            group: Advanced parameters

Parameters may have multi-line descriptions and can have extra attributes defined on new lines below them. Supports:

# @param foo Sets the value of foo in the Example config
#            condition: $bar == 'use_foo'

Supports:

  • condition: an expression to determine if the parameter is used
  • group: comma-separated list of groups, increasing in specificity

Data types are given in the parameter list of the class, or can be given inline for Puppet 3 compatibility:

# @param foo [Integer] Sets the value of foo in the Example config

Used by:

  • PuppetStringsModuleParser

License

This project is licensed under the GPLv3+.

kafo_parsers's People

Contributors

ares avatar domcleal avatar ekohl avatar ehelms avatar mbacovsky avatar jcmcken avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.