Sha256: ab191f9fd233e5de028b32f794426a35f60012097ae9c576faf0c38ffb52bcc7

Contents?: true

Size: 1.74 KB

Versions: 14

Compression:

Stored size: 1.74 KB

Contents

#!/usr/bin/env ruby
require_relative '../lib/cfnlego'
require 'optparse'
require 'ruby-beautify'

include RubyBeautify
options = {resources: [], indent_token: " ", indent_count: 2}
OptionParser.new do |opts|
  opts.banner = "Usage: cfnlego --reousrce resource [options]"

  opts.on("-r", "--resource RESOURCE_TYPE,RESOURCE_LOGICAL_NAME", "Add resource type and logical name") do |r|
    options[:resources] << r
  end

  opts.on("-i", "--indent TOKEN", "Use TOKEN for indent character (default space)") do |i|
    options[:indent_token] = i
  end

  opts.on("-l", "--list", "List supported resources") do
    options[:list_resources] = true
    puts Cfnlego.Resources.sort
    exit
  end

  opts.on("-c", 
          "--indent-count [COUNT]", 
          Integer, 
          "Count of characters to use for indenting. (default: 2)") \
  do |count| 
    options[:indent_count] = count
  end

  opts.on("-h", "--help", "Prints this help") do
    puts opts
    puts <<-EXAMPLE
Example:
  cfnlego                                           \\
    --reousrce AutoScaling::AutoScalingGroup,ASG    \\
    --reousrce IAM::Role,Role                       \\
    --reousrce IAM::InstanceProfile,InstanceProfile \\
EXAMPLE

    exit
  end

  opts.on("-v", "--version", "Show version") do
    puts Cfnlego::VERSION
    exit 
  end
end.parse!

# Constructure Resources
resources = []
options[:resources].each do |r|
  /(.*),(.*)/.match(r) do |m|
    type = m[1]
    name = m[2]
    resources << Cfnlego::Resource.new(type, name)
  end
end

begin 
  puts pretty_string Cfnlego::CloudFormation.new(resources).render, 
                     indent_token: options[:indent_token], 
                     indent_count: options[:indent_count]
rescue RuntimeError => e
  $stderr.puts "Error: #{e.message}"
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
cfnlego-0.4.0 bin/cfnlego
cfnlego-0.3.6 bin/cfnlego
cfnlego-0.3.5 bin/cfnlego
cfnlego-0.3.4 bin/cfnlego
cfnlego-0.3.3 bin/cfnlego
cfnlego-0.3.2 bin/cfnlego
cfnlego-0.3.1 bin/cfnlego
cfnlego-0.3.0 bin/cfnlego
cfnlego-0.2.9 bin/cfnlego
cfnlego-0.2.8 bin/cfnlego
cfnlego-0.2.7 bin/cfnlego
cfnlego-0.2.6 bin/cfnlego
cfnlego-0.2.5 bin/cfnlego
cfnlego-0.2.4 bin/cfnlego