Class: Belt::CLI::EnvironmentCommand
- Inherits:
-
Object
- Object
- Belt::CLI::EnvironmentCommand
- Includes:
- AppDetection
- Defined in:
- lib/belt/cli/environment_command.rb
Constant Summary collapse
- TEMPLATE_DIR =
File.('../../templates/environment', __dir__)
Class Method Summary collapse
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(env_name) ⇒ EnvironmentCommand
constructor
A new instance of EnvironmentCommand.
Methods included from AppDetection
Constructor Details
#initialize(env_name) ⇒ EnvironmentCommand
Returns a new instance of EnvironmentCommand.
29 30 31 32 |
# File 'lib/belt/cli/environment_command.rb', line 29 def initialize(env_name) @env_name = env_name.downcase.gsub(/[^a-z0-9_-]/, '') @app_name = detect_app_name end |
Class Method Details
.run(args) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/belt/cli/environment_command.rb', line 14 def self.run(args) env_name = args.shift if env_name.nil? || env_name.empty? puts 'Usage: belt generate environment <name>' puts "\nExamples:" puts ' belt generate environment dev01' puts ' belt generate environment staging' puts ' belt generate environment prod' exit 1 end new(env_name).generate end |
Instance Method Details
#generate ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/belt/cli/environment_command.rb', line 34 def generate dest_dir = "infrastructure/#{@env_name}" if Dir.exist?(dest_dir) puts "Environment '#{@env_name}' already exists at #{dest_dir}/" exit 1 end puts "Creating environment: #{@env_name}" FileUtils.mkdir_p(dest_dir) templates.each do |template_name, dest_file| dest_path = File.join(dest_dir, dest_file) write_template(template_name, dest_path) puts " create #{dest_path}" end puts "\n✓ Environment '#{@env_name}' created!" puts "\nNext steps:" puts " cd #{dest_dir}" puts ' terraform init' puts ' terraform plan' puts ' terraform apply' end |