forked from puppetlabs/facter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.rb
executable file
·32 lines (25 loc) · 1016 Bytes
/
generate.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env ruby
# frozen_string_literal: true
# Generates a markdown file containing fact documentation.
# usage: ruby generate.rb > facts.md
require 'yaml'
require 'erb'
require 'ostruct'
PATH_TO_SCHEMA = File.join(File.dirname(__FILE__), '../schema/facter.yaml')
PATH_TO_TEMPLATE = File.join(File.dirname(__FILE__), 'template.erb')
schema = YAML.load_file(PATH_TO_SCHEMA)
def format_facts(fact_hash)
scope = OpenStruct.new({
facts: fact_hash
})
erb = if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
ERB.new(File.read(PATH_TO_TEMPLATE), trim_mode: '-')
else
ERB.new(File.read(PATH_TO_TEMPLATE), nil, '-')
end
erb.result(scope.instance_eval { binding })
end
print "## Modern Facts\n\n"
print format_facts(schema.reject { |_name, info| info['hidden'] == true })
print "## Legacy Facts\n\n"
print format_facts(schema.reject { |_name, info| info['hidden'].nil? || info['hidden'] == false })