#!/usr/bin/env ruby $LOAD_PATH.unshift('./lib') require 'optparse' require 'terradoc' # -------------------------------------------------------------------------------- # # Run Terradoc # # -------------------------------------------------------------------------------- # # Pass the command line options to the class and run terradoc # # -------------------------------------------------------------------------------- # def run_terradoc(options) begin Terradoc.new(options) rescue StandardError => e puts "Error: #{e}" puts e.backtrace if options[:verbose] exit(1) end end # -------------------------------------------------------------------------------- # # Process Arguments # # -------------------------------------------------------------------------------- # # This function will process the input from the command line and work out what it # # is that the user wants to see. # # # # This is the main processing function where all the processing logic is handled. # # -------------------------------------------------------------------------------- # def process_arguments options = { :verbose => false } # Enforce the presence of mandatory = %I[] optparse = OptionParser.new do |opts| opts.banner = "Usage: #{$PROGRAM_NAME}" opts.on('-h', '--help', 'Display this screen') do puts opts exit(1) end opts.on('-v', '--verbose', 'Turn on verbose mode') do options[:verbose] = true end opts.on('-o', '--output string', 'Set the name of the output file. [default: README.md]') do |output| options[:output] = output end opts.on('-p', '--path string', 'Set the path for where the terraform code is. [default: current directory]') do |path| options[:path] = path end end begin optparse.parse! missing = mandatory.select { |param| options[param].nil? } raise OptionParser::MissingArgument.new(missing.join(', ')) unless missing.empty? rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e puts e.to_s puts optparse exit end exit 0 if run_terradoc(options) exit 1 end # -------------------------------------------------------------------------------- # # Main() # # -------------------------------------------------------------------------------- # # The main function where all of the heavy lifting and script config is done. # # -------------------------------------------------------------------------------- # def main process_arguments end main # -------------------------------------------------------------------------------- # # End of Script # # -------------------------------------------------------------------------------- # # This is the end - nothing more to see here. # # -------------------------------------------------------------------------------- #