Skip to content

Commit

Permalink
Merge pull request #111 from rodjek/auto_table
Browse files Browse the repository at this point in the history
Change table rake task to update README.md
  • Loading branch information
rodjek authored Jul 17, 2019
2 parents 10a7b91 + 35d0425 commit 330ab64
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ for file in facts/*/centos-*.facts; do cat $file | sed -e 's/CentOS/Scientific/'
for file in facts/*/centos-*.facts; do cat $file | sed -e 's/CentOS/OracleLinux/' > $(echo $file | sed 's/centos/oraclelinux/'); done
```

Then update array `Facter version and Operating System coverage` with output of rake task `table`.
Then update the table in this README by running `bundle exec rake table`

## Supplying custom external facts

Expand Down
14 changes: 11 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,22 @@ task :table do
# Extract the OS list
os_versions = os_facter_matrix.keys.uniq.sort

readme_path = File.expand_path(File.join(__dir__, 'README.md'))
readme = File.read(readme_path).split("\n")
new_readme = readme[0..readme.index { |r| r.start_with?('| ') } - 1]

# Write out a nice table
os_version_width = (os_versions.map{|x| x.size } + [17]).max
puts "| #{'operating system'.center(os_version_width)} |#{facter_versions.map{|x| " #{x} |" }.join}"
puts "| #{'-' * (os_version_width)} |#{facter_versions.map{|x| " --- |" }.join}"
new_readme << "| #{'operating system'.center(os_version_width)} |#{facter_versions.map{|x| " #{x} |" }.join}"
new_readme << "| #{'-' * (os_version_width)} |#{facter_versions.map{|x| " --- |" }.join}"
os_versions.each do |label|
fvs = facter_versions.map{ |facter_version| os_facter_matrix[label][facter_version] || 0 }
row = "| #{label.ljust(os_version_width)} |"
fvs.each { |fv| row += (fv > 0? " #{fv.to_s.center(3)} |" : " |" ) }
puts row
new_readme << row
end

File.open(readme_path, 'w') do |fd|
fd.puts (new_readme + readme[readme.rindex { |r| r.start_with?('| ') } + 1..-1]).join("\n")
end
end

0 comments on commit 330ab64

Please sign in to comment.