class Composify::CLI

Public Class Methods

from_trollop( argv ) click to toggle source
# File lib/composify.rb, line 62
def self.from_trollop( argv )
  opts = Trollop::options(argv) do
    version "composify #{Composify::VERSION}"
    banner "Generate a docker-development environment.\nNOTE: The name of your project is the directory"
    opt :base, "Base image of your application", :type => :string, :required => true
    opt :compilable, "Does your application code needs to be compiled?", :type => :bool, :default => false, :short => "C"
    opt :components, "The names of your application services, ie: api, scheduler, etc.", :type => :strings, :required => true
    opt :resource, "[ resource_name, resource_image ] The resources you will use.  May be specified more than once.", :type => :strings, :multi => true
    opt :force, "Overwrite any files that exist", :type => :bool, :default => false
  end

  opts[:resources] = opts[:resource].map{ |e| parse_resource(e) }

  opts[:root] = Dir.pwd
  opts[:project_name] = File.basename( opts[:root] ).gsub(/[^a-zA-Z0-9_]/, '')

  return opts
end
main( argv ) click to toggle source
# File lib/composify.rb, line 57
def self.main( argv )
  cli = self.new( argv )
  cli.generate
end
new( argv ) click to toggle source
# File lib/composify.rb, line 91
def initialize( argv )
  @argv = ARGV
end
parse_resource( definition ) click to toggle source

definition is an array like this:

resource_name, image

Returns: [{ :name => “<resource_name>”, :image => “<image_url>” }, … ]

# File lib/composify.rb, line 84
def self.parse_resource( definition )
  return {
    :name  => definition[0],
    :image => definition[1]
  }
end

Public Instance Methods

generate() click to toggle source
# File lib/composify.rb, line 99
def generate

  b = binding
  Template::FILE_LIST.each_pair do |_, file|
    template = Template.new( file )
    template.write( b, force: options[:force] )
  end
end
options() click to toggle source
# File lib/composify.rb, line 95
def options
  return @_options ||= self.class.from_trollop( @argv )
end