-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathfacter_cli.rb
More file actions
52 lines (47 loc) · 1.75 KB
/
facter_cli.rb
File metadata and controls
52 lines (47 loc) · 1.75 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# frozen_string_literal: true
require 'puppet_references'
module PuppetReferences
module Facter
class FacterCli < PuppetReferences::Reference
OUTPUT_DIR = PuppetReferences::OUTPUT_DIR + 'openfact'
PREAMBLE_FILE = Pathname.new(__FILE__).dirname + 'facter_cli_preamble.md'
PREAMBLE = PREAMBLE_FILE.read
def initialize(*)
@latest = '/openvox/latest'
super
end
def header_data
{ title: 'Facter: CLI',
toc: 'columns',
canonical: "#{@latest}/cli.html", }
end
def build_all
require 'open3'
puts 'Building CLI documentation page for facter.'
OUTPUT_DIR.mkpath
Bundler.with_unbundled_env do
Open3.capture3("BUNDLE_GEMFILE=#{PuppetReferences::FACTER_DIR}/Gemfile bundle update")
end
raw_text, err, exit_code = Open3.capture3("BUNDLE_GEMFILE=#{PuppetReferences::FACTER_DIR}/Gemfile bundle exec facter man")
if exit_code != 0
puts "Encountered an error while building the facter cli docs, will abort: #{err}"
return
end
require 'pandoc-ruby'
markdown_text = PandocRuby.new(raw_text, from: 'man').to_markdown
content = make_header(header_data) + PREAMBLE + markdown_text
filename = OUTPUT_DIR + 'cli.md'
filename.open('w') { |f| f.write(content) }
puts 'CLI documentation is done!'
end
def build_v3_cli
OUTPUT_DIR.mkpath
filename = OUTPUT_DIR + 'cli.md'
man_filepath = PuppetReferences::FACTER_DIR + 'man/man8/facter.8'
raw_text = PuppetReferences::Util.convert_man(man_filepath)
content = make_header(header_data) + raw_text
filename.open('w') { |f| f.write(content) }
end
end
end
end