Sha256: 206bfb1fd28a21b63a1c3648c2e45bd4ce4eaa785be4f53e5b5d0263b48dff19

Contents?: true

Size: 1.35 KB

Versions: 6

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

require 'lino'

module RubyEasyRSA
  module Commands
    class Base
      attr_reader :binary

      def initialize(binary: nil)
        @binary = binary || RubyEasyRSA.configuration.binary
      end

      def stdin
        nil
      end

      def stdout
        $stdout
      end

      def stderr
        $stderr
      end

      def execute(parameters = {})
        parameters = resolve_parameters(parameters)

        do_before(parameters)
        result = build_and_execute_command(parameters)
        do_after(parameters)

        result
      end

      private

      def build_and_execute_command(parameters)
        command = configure_command(instantiate_builder, parameters).build

        command.execute(stdin:, stdout:, stderr:)
      end

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

      def do_before(_); end

      def configure_command(builder, _parameters)
        builder
      end

      def do_after(_); end

      def resolve_parameters(parameters)
        parameter_defaults(parameters)
          .merge(parameters)
          .merge(parameter_overrides(parameters))
      end

      def parameter_defaults(_parameters)
        {}
      end

      def parameter_overrides(_parameters)
        {}
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruby_easy_rsa-0.14.0.pre.2 lib/ruby_easy_rsa/commands/base.rb
ruby_easy_rsa-0.14.0.pre.1 lib/ruby_easy_rsa/commands/base.rb
ruby_easy_rsa-0.13.0 lib/ruby_easy_rsa/commands/base.rb
ruby_easy_rsa-0.12.0.pre.7 lib/ruby_easy_rsa/commands/base.rb
ruby_easy_rsa-0.12.0.pre.6 lib/ruby_easy_rsa/commands/base.rb
ruby_easy_rsa-0.12.0.pre.5 lib/ruby_easy_rsa/commands/base.rb