Sha256: 7d349cd647d449f6398914852e67837b10bdbe4149b3b4dc3d111a574771d385

Contents?: true

Size: 1.61 KB

Versions: 30

Compression:

Stored size: 1.61 KB

Contents

class Terraspace::CLI::New
  class Test < Thor::Group
    include Thor::Actions
    include Terraspace::CLI::New::Helpers

    argument :name, required: false

    def self.options
      [
        [:force, aliases: %w[y], type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files"],
        [:test_name, desc: "Test name. Defaults to the project, module or stack name"],
        [:type, default: "stack", desc: "project, stack or module"],
      ]
    end
    options.each { |args| class_option(*args) }

  private
    def type
      valid_types = %w[project stack module]
      type = @options[:type]
      valid_types.include?(type) ? type : "project" # fallback to project if user provides invalid type
    end

    def test_name
      options[:test_name] || name
    end

    def dest
      map = {
        project: ".", # Terraspace.root
        stack:   "app/stacks/#{name}",
        module:  "app/modules/#{name}",
      }
      map[type.to_sym]
    end

    def test_template_source(template, type)
      source = Terraspace::CLI::New::Source::Test.new(self, @options)
      source.set_source_paths(template, type)
    end

  public

    def create
      if type != 'project' && name.nil?
        puts "ERROR: require NAME for type stack and module".color(:red)
        exit 1
      end
      test_template_source(@options[:lang], type)
      puts "=> Creating #{type} test: #{name}"
      directory ".", dest
    end

    # Used in ERB template
    # rspec-terraspace/lib/templates/stack/test/spec/fixtures/config/terraform/provider.tf.tt
    def autodetect_provider
      Terraspace::Plugin.autodetect
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
terraspace-2.2.17 lib/terraspace/cli/new/test.rb
terraspace-2.2.16 lib/terraspace/cli/new/test.rb
terraspace-2.2.15 lib/terraspace/cli/new/test.rb
terraspace-2.2.14 lib/terraspace/cli/new/test.rb
terraspace-2.2.13 lib/terraspace/cli/new/test.rb
terraspace-2.2.12 lib/terraspace/cli/new/test.rb
terraspace-2.2.11 lib/terraspace/cli/new/test.rb
terraspace-2.2.10 lib/terraspace/cli/new/test.rb
terraspace-2.2.9 lib/terraspace/cli/new/test.rb
terraspace-2.2.8 lib/terraspace/cli/new/test.rb
terraspace-2.2.7 lib/terraspace/cli/new/test.rb
terraspace-2.2.6 lib/terraspace/cli/new/test.rb
terraspace-2.2.5 lib/terraspace/cli/new/test.rb
terraspace-2.2.4 lib/terraspace/cli/new/test.rb
terraspace-2.2.3 lib/terraspace/cli/new/test.rb
terraspace-2.2.2 lib/terraspace/cli/new/test.rb
terraspace-2.2.1 lib/terraspace/cli/new/test.rb
terraspace-2.2.0 lib/terraspace/cli/new/test.rb
terraspace-2.1.7 lib/terraspace/cli/new/test.rb
terraspace-2.1.6 lib/terraspace/cli/new/test.rb