Class: Composify::CLI
- Inherits:
-
Object
- Object
- Composify::CLI
- Defined in:
- lib/composify.rb
Class Method Summary collapse
- .from_trollop(argv) ⇒ Object
- .main(argv) ⇒ Object
-
.parse_resource(definition) ⇒ Object
definition is an array like this: [ resource_name, image ] Returns: [{ :name => “<resource_name>”, :image => “<image_url>” }, … ].
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(argv) ⇒ CLI
constructor
A new instance of CLI.
- #options ⇒ Object
Constructor Details
#initialize(argv) ⇒ CLI
Returns a new instance of CLI.
91 92 93 |
# File 'lib/composify.rb', line 91 def initialize( argv ) @argv = ARGV end |
Class Method Details
.from_trollop(argv) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/composify.rb', line 62 def self.from_trollop( argv ) opts = Trollop::(argv) do version "composify #{Composify::VERSION}" "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) ⇒ Object
57 58 59 60 |
# File 'lib/composify.rb', line 57 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>” }, … ]
84 85 86 87 88 89 |
# File 'lib/composify.rb', line 84 def self.parse_resource( definition ) return { :name => definition[0], :image => definition[1] } end |
Instance Method Details
#generate ⇒ Object
99 100 101 102 103 104 105 106 |
# 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: [:force] ) end end |
#options ⇒ Object
95 96 97 |
# File 'lib/composify.rb', line 95 def return @_options ||= self.class.from_trollop( @argv ) end |