Class: Composify::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/composify.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



90
91
92
# File 'lib/composify.rb', line 90

def initialize( argv )
  @argv = ARGV
end

Class Method Details

.from_trollop(argv) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/composify.rb', line 61

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( Dir.pwd ).gsub(/[^a-zA-Z0-9_]/, '')

  return opts
end

.main(argv) ⇒ Object



56
57
58
59
# File 'lib/composify.rb', line 56

def self.main( argv )
  cli = self.new( argv )
  cli.generate
end

.parse_resource(definition) ⇒ Object

definition is an array like this:

resource_name, image

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



83
84
85
86
87
88
# File 'lib/composify.rb', line 83

def self.parse_resource( definition )
  return {
    :name  => definition[0],
    :image => definition[1]
  }
end

Instance Method Details

#generateObject



98
99
100
101
102
103
104
# File 'lib/composify.rb', line 98

def generate
  b = binding
  Template::FILE_LIST.each_pair do |_, file|
    template = Template.new( file )
    template.write( b, force: options[:force] )
  end
end

#optionsObject



94
95
96
# File 'lib/composify.rb', line 94

def options
  return @_options ||= self.class.from_trollop( @argv )
end