Created
December 7, 2016 01:57
-
-
Save temyers/2e25b549cd9077906127fcb90593d8df to your computer and use it in GitHub Desktop.
This utility makes it easy to convert a properties file specified in the _file_to_update_ variable to Markdown table format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## | |
| ## This utility makes it easy to convert a properties file specified in the _file_to_update_ variable to Markdown table format | |
| ## Takes a properties file in the form: | |
| ## `key=value` | |
| ## | |
| ## It outputs each value in the form: | |
| ## `| key | value |` | |
| ## | |
| ## Optional properties, denoted by being commented out, are output as `<not set>` | |
| def isCommentOrBlank?(line) | |
| return line.start_with?('#') || line.strip.empty?() | |
| end | |
| file_to_update="path/to/properties_file" | |
| lines = File.open(file_to_update).read | |
| lines.each_line do |line| | |
| optionalProperty=/^#([^=]+)=(.+)$/ | |
| line.match(optionalProperty) do |m| | |
| name=m[1].strip | |
| value=m[2].strip | |
| env_property=name.gsub('.','/').downcase | |
| puts "| #{name} | <not set> |" | |
| end | |
| if ( isCommentOrBlank?(line) ) then | |
| # ignore | |
| else | |
| name_value = line.split('=') | |
| name=name_value[0].strip | |
| value=name_value[1].strip | |
| env_property=name.gsub('.','/').downcase | |
| new_line="| #{name} | #{value}" | |
| puts new_line | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment