Sha256: 66e464b21749bc6f69fa571f2211f142bc7d96b7bf7b42155d6370e697441899

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

require 'lino'

module RubyTerraform
  module Commands
    class Base
      attr_reader :binary

      def initialize(binary: nil, logger: nil)
        @binary = binary || RubyTerraform.configuration.binary
        @logger = logger || RubyTerraform.configuration.logger
      end

      def 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

2 entries across 2 versions & 1 rubygems

Version Path
ruby-terraform-0.27.0.pre.pre.2 lib/ruby_terraform/commands/base.rb
ruby-terraform-0.27.0.pre.pre.1 lib/ruby_terraform/commands/base.rb