class Confmake::Command
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/confmake/command.rb, line 9 def initialize *args @env_variables = {} super *args end
Public Instance Methods
execute()
click to toggle source
# File lib/confmake/command.rb, line 25 def execute if version? puts Confmake::VERSION return 0 end if yaml? save_as_yaml() return 0 end if json? save_as_json() return 0 end if configuration_filename.nil? puts 'Specify a template file or use --help for usage information' return 0 end if File.exists? configuration_filename swap_config configuration_filename return 0 else puts "Error: Configuration template file with name #{configuration_filename} does not exist" return 1 end end
gather_variables()
click to toggle source
# File lib/confmake/command.rb, line 55 def gather_variables @env_variables = Confmake::EnvironmentVariableReader.read_variables if include_persisted_shell_variables? if !property_file.nil? and File.exists? property_file @env_variables = Confmake::PropertyFileVariableReader.read_variables_from_file property_file puts @env_variables end process_envvars() if envvars end
help(*args)
click to toggle source
Calls superclass method
# File lib/confmake/command.rb, line 14 def help *args return [ "This is confmake version #{Confmake::VERSION}", super ].join("\n") end
parse_envvars()
click to toggle source
# File lib/confmake/command.rb, line 117 def parse_envvars gather_variables() parsed_variables = Confmake::BashParser.parse_user_input @env_variables puts "Interpreted user variables: #{parsed_variables}" if verbose? parsed_variables end
process_envvars()
click to toggle source
# File lib/confmake/command.rb, line 82 def process_envvars envvars.each { |envvar| key_and_value = envvar.split(/=/, 2) key = key_and_value.first value = key_and_value.last if key_and_value.count != 2 puts "Invalid envvar specified #{key} and #{value}" return 1 end @env_variables[key.to_sym]=value } if verbose? puts "Environment variables:" @env_variables.each { |var| puts "#{var.first} = #{var.last}" } end end
run(*args)
click to toggle source
Calls superclass method
# File lib/confmake/command.rb, line 21 def run *args super *args end
save_as_json()
click to toggle source
# File lib/confmake/command.rb, line 110 def save_as_json @env_variables = parse_envvars() puts "Writing #{output_filename}" env_variables_json = @env_variables.to_json write_file env_variables_json, output_filename end
save_as_yaml()
click to toggle source
# File lib/confmake/command.rb, line 103 def save_as_yaml @env_variables = parse_envvars() puts "Writing #{output_filename}" env_variables_yaml = @env_variables.to_yaml write_file env_variables_yaml, output_filename end
swap_config(configuration_filename)
click to toggle source
# File lib/confmake/command.rb, line 66 def swap_config configuration_filename output_filename_default = configuration_filename + '.out' if output_filename.nil? configuration_template = Confmake::ConfigurationFileReader.read configuration_filename gather_variables() begin output = configuration_template % @env_variables rescue KeyError => error puts "#{error.message}. Your configuration requires this variable, but no environment variable was found or specified." exit(1) end write_file output, output_filename || output_filename_default end
write_file(output_file_contents, output_filename)
click to toggle source
# File lib/confmake/command.rb, line 124 def write_file output_file_contents, output_filename return File.write output_filename, output_file_contents unless File.exists? output_filename if File.exists? output_filename and force? puts "Overwriting #{output_filename}..." File.write output_filename, output_file_contents else puts "#{output_filename} already exists, use the --force flag to overwrite" end end