Sha256: 204700e79d619d94367401ea2cb79fe96f720ab5b9c688f502609e7385f0e847

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

require "aws_ec2_list/version"
require 'virtus'
require 'aws-sdk'
require 'tabularize'

module AwsEc2List
  def self.call(*args)
    defaults = parse_args(args)
    if defaults
      DescribeInstances.new(defaults).call
    else
      DescribeInstances.new.call
    end
  end

  private
  def self.parse_args(args)
    return nil if args.empty?
    return args.first if args.first.is_a?(Hash)
    option_string, default_args = args

    option_string = option_string.first

    if option_string && default_args
      option_hash = option_string_to_hash(option_string)
      option_hash.merge(default_args)

    elsif option_string
      option_string_to_hash(option_string)

    end
  end

  def self.option_string_to_hash(option_string)
    option_array = option_string.split("--").reject { |o| o.empty? }
    option_array = option_array.map{ |opt| opt.split("=") }.flatten

    option_hash = Hash[*option_array]

    option_hash.keys.each do |key|
      option_hash[key.to_sym] = option_hash.delete(key)
    end

    option_hash
  end
end

require_relative "aws_ec2_list/describe_instances"

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aws-ec2-list-0.2.1 lib/aws_ec2_list.rb
aws-ec2-list-0.2.0 lib/aws_ec2_list.rb