Sha256: 08e0eda9bf94981ae2643f08d73a107e5b6c1cea8d6cf1ad3208b2347415ec14

Contents?: true

Size: 1.26 KB

Versions: 10

Compression:

Stored size: 1.26 KB

Contents

require 'lino'

module RubyTerraform
  module Commands
    class Base
      attr_reader :binary

      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 stdin
        @stdin
      end

      def stdout
        @stdout
      end

      def stderr
        @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)
      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

10 entries across 10 versions & 1 rubygems

Version Path
ruby-terraform-0.35.0.pre.pre.1 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.34.0 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.33.0.pre.pre.1 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.32.0 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.31.0.pre.pre.3 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.31.0.pre.pre.2 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.31.0.pre.pre.1 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.30.0 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.29.0.pre.pre.2 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.29.0.pre.pre.1 lib/ruby_terraform/commands/base.rb