class Aeolus::CLI::BaseCommand

This will house some methods that multiple Command classes need to use.

Attributes

options[RW]

Public Class Methods

new(opts={}, logger=nil) click to toggle source
# 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

Protected Instance Methods

is_file?(path) click to toggle source

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
is_uuid?(id) click to toggle source
# 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
logger(logger=nil) click to toggle source
# 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
not_implemented() click to toggle source
# File lib/aeolus_cli/command/base_command.rb, line 39
def not_implemented
  "This option or combination is not yet implemented"
end
quit(code) click to toggle source
# File lib/aeolus_cli/command/base_command.rb, line 76
def quit(code)
  exit(code)
end
read_file(path) click to toggle source
# 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
validate_xml_document(schema_path, xml_string) click to toggle source
# 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