Sha256: c3c2196b694c40240a47465484a0290c6e5caa3c3ec1ad1c37ca63a7d205729e

Contents?: true

Size: 1.45 KB

Versions: 34

Compression:

Stored size: 1.45 KB

Contents

require 'lino'
require_relative '../errors'

module RubyTerraform
  module Commands
    class Base
      def initialize(
          binary: nil, logger: nil, stdin: nil, stdout: nil, stderr: nil)
        @binary = binary || RubyTerraform.configuration.binary
        @logger = logger || RubyTerraform.configuration.logger
        @stdin = stdin || RubyTerraform.configuration.stdin
        @stdout = stdout || RubyTerraform.configuration.stdout
        @stderr = stderr || RubyTerraform.configuration.stderr
      end

      def execute(opts = {})
        builder = instantiate_builder

        do_before(opts)
        command = configure_command(builder, opts).build
        logger.debug("Running '#{command.to_s}'.")

        command.execute(
            stdin: stdin,
            stdout: stdout,
            stderr: stderr
        )
        do_after(opts)
      rescue Open4::SpawnError
        message = "Failed while running '#{command_name}'."
        logger.error(message)
        raise Errors::ExecutionError, message
      end

      protected

      attr_reader :binary, :logger, :stdin, :stdout, :stderr

      def command_name
        self.class.to_s.split("::")[-1].downcase
      end

      def instantiate_builder
        Lino::CommandLineBuilder
            .for_command(binary)
            .with_option_separator('=')
      end

      def do_before(opts)
      end

      def configure_command(builder, opts)
      end

      def do_after(opts)
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
ruby-terraform-0.65.0.pre.1 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.64.0 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.63.0.pre.1 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.62.0 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.61.0.pre.1 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.60.0 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.59.0.pre.2 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.59.0.pre.1 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.58.0 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.57.0.pre.2 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.57.0.pre.1 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.56.0 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.55.0.pre.1 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.54.0 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.53.0.pre.2 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.53.0.pre.1 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.52.0 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.51.0.pre.3 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.51.0.pre.2 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.51.0.pre.1 lib/ruby_terraform/commands/base.rb