Sha256: 152b3e86688b93e8b63203cd9a1bcce5ea584bf72126a117499e0b651f874321

Contents?: true

Size: 1.04 KB

Versions: 8

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require 'lino'

module RubyFly
  module Commands
    class Base
      attr_reader :binary, :stdin, :stdout, :stderr

      def initialize(opts = {})
        @binary = opts[:binary] || RubyFly.configuration.binary
        @stdin = stdin || RubyFly.configuration.stdin
        @stdout = stdout || RubyFly.configuration.stdout
        @stderr = stderr || RubyFly.configuration.stderr
      end

      def execute(opts = {})
        do_before(opts)
        do_around(opts) do |new_opts|
          configure_command(instantiate_builder, new_opts)
            .build
            .execute(stdin: stdin, stdout: stdout, stderr: stderr)
        end
        do_after(opts)
      end

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

      def do_before(opts); end

      def do_around(opts, &block)
        block.call(opts)
      end

      def configure_command(builder, _opts)
        builder
      end

      def do_after(opts); end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ruby_fly-0.40.0.pre.4 lib/ruby_fly/commands/base.rb
ruby_fly-0.40.0.pre.3 lib/ruby_fly/commands/base.rb
ruby_fly-0.40.0.pre.2 lib/ruby_fly/commands/base.rb
ruby_fly-0.40.0.pre.1 lib/ruby_fly/commands/base.rb
ruby_fly-0.39.0 lib/ruby_fly/commands/base.rb
ruby_fly-0.38.0.pre.5 lib/ruby_fly/commands/base.rb
ruby_fly-0.38.0.pre.4 lib/ruby_fly/commands/base.rb
ruby_fly-0.38.0.pre.3 lib/ruby_fly/commands/base.rb