This will house some methods that multiple Command classes need to use.
# File lib/aeolus_cli/command/base_command.rb, line 26 def initialize(opts={}, logger=nil) begin logger(logger) @options = opts @config_location = "~/.aeolus-cli" @config = load_config configure_active_resource rescue => e handle_exception(e) end end
TODO: Consider ripping all this file-related stuff into a module or class for better encapsulation and testability
# File lib/aeolus_cli/command/base_command.rb, line 68 def is_file?(path) full_path = File.expand_path(path) if File.exist?(full_path) && !File.directory?(full_path) return true end false end
# File lib/aeolus_cli/command/base_command.rb, line 86 def is_uuid?(id) uuid = Regexp.new('[\w]{8}[-][\w]{4}[-][\w]{4}[-][\w]{4}[-][\w]{12}') uuid.match(id).nil? ? false : true end
# File lib/aeolus_cli/command/base_command.rb, line 43 def logger(logger=nil) @logger ||= logger unless @logger @logger = Logger.new(STDOUT) @logger.level = Logger::INFO @logger.datetime_format = "%Y-%m-%d %H:%M:%S" end return @logger end
# File lib/aeolus_cli/command/base_command.rb, line 39 def not_implemented "This option or combination is not yet implemented" end
# File lib/aeolus_cli/command/base_command.rb, line 76 def quit(code) exit(code) end
# File lib/aeolus_cli/command/base_command.rb, line 53 def read_file(path) begin full_path = File.expand_path(path) if is_file?(path) File.read(full_path) else return nil end rescue nil end end
# File lib/aeolus_cli/command/base_command.rb, line 80 def validate_xml_document(schema_path, xml_string) schema = Nokogiri::XML::RelaxNG(File.read(schema_path)) doc = Nokogiri::XML xml_string schema.validate(doc) end